From d943154ff8099b50810807aa8319dfc77a134d2e Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Mon, 19 Sep 2016 11:39:50 +0200
Subject: [PATCH] fixup! ERP5Web: redirect to the minimum URL if verbose
 languages exist in URL.

so that we keep the query string in the redirect url if exists.
---
 product/ERP5/Document/WebSite.py  | 3 +++
 product/ERP5/tests/testERP5Web.py | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/product/ERP5/Document/WebSite.py b/product/ERP5/Document/WebSite.py
index f49a6195a8..f7de54cd9f 100644
--- a/product/ERP5/Document/WebSite.py
+++ b/product/ERP5/Document/WebSite.py
@@ -182,6 +182,9 @@ class WebSite(WebSection):
               redirect_path_list.append(name)
             redirect_path_list.extend(reversed(request['TraversalRequestNameStack']))
             request['minimum_language_redirect_url'] = '/'.join(redirect_path_list)
+            query_string = request.get('QUERY_STRING')
+            if query_string:
+              request['minimum_language_redirect_url'] += '?' + query_string
           return self.getOriginalDocument().asContext(id=name)
       return WebSection.getExtensibleContent(self, request, name)
 
diff --git a/product/ERP5/tests/testERP5Web.py b/product/ERP5/tests/testERP5Web.py
index 493d62b55c..841fdc2cdd 100644
--- a/product/ERP5/tests/testERP5Web.py
+++ b/product/ERP5/tests/testERP5Web.py
@@ -979,6 +979,8 @@ Hé Hé Hé!""", page.asText().strip())
                      websection_fr.absolute_url())
     self.assertEqual(self.publish(webpage_bg_en_fr.absolute_url(relative=1)).getHeader('location'),
                      webpage_fr.absolute_url())
+    self.assertEqual(self.publish(website_bg_en_fr.absolute_url(relative=1)+'?a=b&c=d').getHeader('location'),
+                     website_fr.absolute_url()+'?a=b&c=d')
 
     # /bg/en/xxx should be redirected to /xxx where en is the default language
     website_bg_en = self.portal.restrictedTraverse(
@@ -993,6 +995,8 @@ Hé Hé Hé!""", page.asText().strip())
                      websection.absolute_url())
     self.assertEqual(self.publish(webpage_bg_en.absolute_url(relative=1)).getHeader('location'),
                      webpage.absolute_url())
+    self.assertEqual(self.publish(websection_bg_en.absolute_url(relative=1)+'?a=b&c=d').getHeader('location'),
+                     websection.absolute_url()+'?a=b&c=d')
 
     # /en/xxx should be redirected to /xxx where en is the default language
     website_en = self.portal.restrictedTraverse(
@@ -1007,6 +1011,8 @@ Hé Hé Hé!""", page.asText().strip())
                      websection.absolute_url())
     self.assertEqual(self.publish(webpage_en.absolute_url(relative=1)).getHeader('location'),
                      webpage.absolute_url())
+    self.assertEqual(self.publish(webpage_en.absolute_url(relative=1)+'?a=b&c=d').getHeader('location'),
+                     webpage.absolute_url()+'?a=b&c=d')
 
   def test_13_DocumentCache(self):
     """
-- 
2.30.9