Fix the test case
[metaproxy-moved-to-github.git] / src / filter_http_rewrite.cpp
index ff1a25c..249a757 100644 (file)
@@ -200,22 +200,22 @@ const std::string yf::HttpRewrite::search_replace(
                 = groups_bynum.find(i);
             if (it != groups_bynum.end()) 
             {   //it is
-                std::string name = it->second;
                 if (!what[i].str().empty())
-                    vars[name] = what[i];
+                    vars[it->second] = what[i];
             }
 
         }
         //prepare replacement string
         std::string rvalue = sub_vars(uri_pat, vars);
-        //rewrite value
-        std::string rhvalue = what.prefix().str() 
-            + rvalue + what.suffix().str();
         yaz_log(YLOG_LOG, "! Rewritten '%s' to '%s'", 
                 what.str(0).c_str(), rvalue.c_str());
-        out += rhvalue;
+        out.append(start, what[0].first);
+        out.append(rvalue);
         start = what[0].second; //move search forward
     }
+    //if we had a match cat the last part
+    if (start != txt.begin())
+        out.append(start, end);
     return out;
 }