aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-08-28 10:35:30 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-08-28 10:35:30 +0300
commit2fc8e8f157b33051af12fa6f432401bcffd01b15 (patch)
tree9e294486c47b232fd35d04845ae1aa168bd6f308
parent46d7e555623b61e9e4b33e14a682d8d9fc9c9b1a (diff)
downloadsmap-master.tar.gz
smap-master.tar.bz2
transform: fix replacement of numbered pattern instancesHEADmaster
* modules/sed/transform.c (_single_transform_name_to_slist): Avoid duplicating initial prefix if replace is not needed. * tests/sed.at: Add new testcases.
-rw-r--r--modules/sed/transform.c8
-rw-r--r--tests/sed.at9
2 files changed, 12 insertions, 5 deletions
diff --git a/modules/sed/transform.c b/modules/sed/transform.c
index 67e0de8..ec7983f 100644
--- a/modules/sed/transform.c
+++ b/modules/sed/transform.c
@@ -626,10 +626,6 @@ _single_transform_name_to_slist (struct transform *tr,
626 626
627 disp = rmp[0].rm_eo; 627 disp = rmp[0].rm_eo;
628 628
629 if (rmp[0].rm_so)
630 if (transform_append (tr, slist, input, rmp[0].rm_so))
631 return 1;
632
633 nmatches++; 629 nmatches++;
634 if (tf->match_number && nmatches < tf->match_number) 630 if (tf->match_number && nmatches < tf->match_number)
635 { 631 {
@@ -639,6 +635,10 @@ _single_transform_name_to_slist (struct transform *tr,
639 continue; 635 continue;
640 } 636 }
641 637
638 if (rmp[0].rm_so)
639 if (transform_append (tr, slist, input, rmp[0].rm_so))
640 return 1;
641
642 for (segm = tf->repl_head; segm; segm = segm->next) 642 for (segm = tf->repl_head; segm; segm = segm->next)
643 { 643 {
644 switch (segm->type) 644 switch (segm->type)
diff --git a/tests/sed.at b/tests/sed.at
index 0f432c5..39dd99d 100644
--- a/tests/sed.at
+++ b/tests/sed.at
@@ -9,15 +9,22 @@ AT_DATA([smapd.conf],
9module sed sed 9module sed sed
10database dequote sed 's/<(.*)>/\1/g' 10database dequote sed 's/<(.*)>/\1/g'
11database default sed 's/ok-(.*)/\1/' 11database default sed 's/ok-(.*)/\1/'
12database n sed 's/s/@/2'
13database g sed 's/s/@/2g'
14dispatch map eq n database n
15dispatch map eq g database g
12dispatch key like <*> transform key dequote 16dispatch key like <*> transform key dequote
13dispatch default database default 17dispatch default database default
14]) 18])
15AT_CHECK([smaptest -c smapd.conf test ok-word test word test '<ok-word>' 19AT_CHECK([smaptest -c smapd.conf test ok-word test word test '<ok-word>' n password g passwords
16], 20],
17[0], 21[0],
18[test ok-word: OK word 22[test ok-word: OK word
19test word: NOTFOUND 23test word: NOTFOUND
20test <ok-word>: OK word 24test <ok-word>: OK word
25n password: OK pas@word
26g passwords: OK pas@word@
21]) 27])
28
22AT_CLEANUP 29AT_CLEANUP
23 30

Return to:

Send suggestions and report system problems to the System administrator.