evergreen.lpad_number_substrings doesn't handle internal substring matches properly
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Evergreen |
Fix Released
|
Low
|
Unassigned |
Bug Description
All versions with evergreen.
The evergreen.
As an example, this monograph part label '2015 01 (Jan)' will call this function with a pad of '0' and a length of 10, which should result in '0000002015 0000000001 (Jan)' (I'm ignoring the naco_normalize step here, it's not relevant to the issue) but because the 01 is also present in 2015, the result is '000000200000000015 0000000001 (Jan)' The fix is to make the s/// at the bottom of the function (circa 2.7) more picky about its matches. I've found out what it needs to be, now I need to learn about these tests I keep hearing so much about. :)
If you are impatient and want to help test before I have time to figure the pgtap testing part out, this is the function that works for me, note the s/(^|\D)
CREATE OR REPLACE FUNCTION evergreen.
RETURNS text
LANGUAGE plperlu
AS $function$
my $string = shift;
my $pad = shift;
my $len = shift;
my $find = $len - 1;
while ($string =~ /(?:^|\
my $padded = $1;
$padded = $pad x ($len - length($padded)) . $padded;
$string =~ s/(^|\D)
}
return $string;
$function$
This should be an easy test to write, I'm hoping I can get to it soon.
description: | updated |
summary: |
- evergreen.lpad_number_substrings doesn't handle "internal" substrings - properly + evergreen.lpad_number_substrings doesn't handle internal substring + matches properly |
Changed in evergreen: | |
milestone: | none → 2.next |
Changed in evergreen: | |
assignee: | nobody → Galen Charlton (gmc) |
Changed in evergreen: | |
milestone: | 2.next → 2.10-beta |
Changed in evergreen: | |
status: | Fix Committed → Fix Released |
How about something like this?
CREATE OR REPLACE FUNCTION evergreen. lpad_number_ substrings( text, text, integer)
RETURNS text
LANGUAGE plperlu
AS $function$
my $string = shift;
my $pad = shift;
my $len = shift;
$string =~ s/([0-9]+)/$pad x ($len - length($1)) . $1/eg;
return $string;
$function$