Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/bug-1026379 into 
lp:zorba.

Requested reviews:
  Paul J. Lucas (paul-lucas)
Related bugs:
  Bug #1026379 in Zorba: ""q" flag for fn:replace() is ignored"
  https://bugs.launchpad.net/zorba/+bug/1026379

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/bug-1026379/+merge/115877

No longer checking captured subgroups in replacement string when 'q' flag is 
given.
-- 
https://code.launchpad.net/~paul-lucas/zorba/bug-1026379/+merge/115877
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-07-19 13:47:33 +0000
+++ ChangeLog	2012-07-20 02:55:23 +0000
@@ -38,6 +38,7 @@
     for calling TypeOps::get_atomic_type_code() from
     SchemaValidatorImpl::isPossibleSimpleContentRevalImpl())
   * Fixed bug #867357 (Improved parser error messages)
+  * Fixed bug #1026379 ("q" flag for fn:replace() is ignored)
   * Fixed bug #932314 (non-comparable values must be treated as distinct by
     fn:distinct-values)
   * Fixed bug #1015580 (Add base64_streambuf / replace inefficient base64 code)

=== modified file 'src/runtime/strings/strings_impl.cpp'
--- src/runtime/strings/strings_impl.cpp	2012-07-12 17:29:55 +0000
+++ src/runtime/strings/strings_impl.cpp	2012-07-20 02:55:23 +0000
@@ -1541,7 +1541,7 @@
   zstring input;
   zstring flags;
   zstring pattern;
-  zstring replacement, replacement2;
+  zstring replacement;
   zstring resStr;
   store::Item_t item;
   bool tmp;
@@ -1585,24 +1585,27 @@
       err::FORX0003, ERROR_PARAMS( pattern ), ERROR_LOC( loc )
     );
 
-  { // local scope
+  if ( flags.find( 'q' ) == zstring::npos ) {
+
+    // First, count the number of capturing groups.
+    bool got_paren = false;
     int num_capturing_groups = 0;
-
-    bool got_paren = false;
     FOR_EACH( zstring, c, pattern ) {
       if ( got_paren && *c != '?' )
         ++num_capturing_groups;
       got_paren = *c == '(';
     }
 
-    bool got_backslash = false, got_dollar = false;
+    bool got_backslash = false;
+    bool got_dollar = false;
+    zstring temp_replacement;
     FOR_EACH( zstring, c, replacement ) {
       if ( got_backslash ) {
         switch ( *c ) {
           case '\\':
           case '$':
-            replacement2 += '\\';
-            replacement2 += *c;
+            temp_replacement += '\\';
+            temp_replacement += *c;
             got_backslash = false;
             continue;
           default:
@@ -1621,8 +1624,8 @@
             ERROR_LOC( loc )
           );
         if ( *c - '0' <= num_capturing_groups ) {
-          replacement2 += '$';
-          replacement2 += *c;
+          temp_replacement += '$';
+          temp_replacement += *c;
         }
         got_dollar = false;
         continue;
@@ -1635,7 +1638,7 @@
           got_dollar = true;
           break;
         default:
-          replacement2 += *c;
+          temp_replacement += *c;
           break;
       }
     } // FOR_EACH
@@ -1651,13 +1654,14 @@
         ERROR_PARAMS( replacement, ZED( TrailingChar_3 ), '$' ),
         ERROR_LOC( loc )
       );
-  } // local scope
+    replacement = temp_replacement;
+  }
 
   try
   {
     zstring lib_pattern;
     convert_xquery_re( pattern, &lib_pattern, flags.c_str() );
-    utf8::replace_all(input, lib_pattern, flags.c_str(), replacement2, &resStr);
+    utf8::replace_all(input, lib_pattern, flags.c_str(), replacement, &resStr);
   }
   catch(XQueryException& ex)
   {

=== added file 'test/rbkt/ExpQueryResults/zorba/string/ReplaceFunc/replace20.xml.res'
--- test/rbkt/ExpQueryResults/zorba/string/ReplaceFunc/replace20.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/string/ReplaceFunc/replace20.xml.res	2012-07-20 02:55:23 +0000
@@ -0,0 +1,1 @@
+$oo

=== added file 'test/rbkt/Queries/zorba/string/ReplaceFunc/replace20.xq'
--- test/rbkt/Queries/zorba/string/ReplaceFunc/replace20.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/string/ReplaceFunc/replace20.xq	2012-07-20 02:55:23 +0000
@@ -0,0 +1,1 @@
+fn:replace("foo", "f", "$", "q")

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to