Browse Source

Fix URL search fragment decoding

Fixes #45
Thibaut 12 years ago
parent
commit
ce31de5c3f

+ 3 - 0
assets/javascripts/lib/util.coffee

@@ -260,6 +260,9 @@ ESCAPE_REGEXP = /([.*+?^=!:${}()|\[\]\/\\])/g
 $.escapeRegexp = (string) ->
   string.replace ESCAPE_REGEXP, "\\$1"
 
+$.urlDecode = (string) ->
+  decodeURIComponent string.replace(/\+/g, '%20')
+
 #
 # Miscellaneous
 #

+ 1 - 1
assets/javascripts/views/search/search.coffee

@@ -116,4 +116,4 @@ class app.views.Search extends app.View
       value
 
   getHashValue: ->
-    try (new RegExp "##{SEARCH_PARAM}=(.*)").exec(decodeURIComponent location.hash)?[1] catch
+    try (new RegExp "##{SEARCH_PARAM}=(.*)").exec($.urlDecode location.hash)?[1] catch

+ 2 - 2
assets/javascripts/views/search/search_scope.coffee

@@ -76,9 +76,9 @@ class app.views.SearchScope extends app.View
 
   extractHashValue: ->
     if value = @getHashValue()
-      newHash = decodeURIComponent(location.hash).replace "##{SEARCH_PARAM}=#{value} ", "##{SEARCH_PARAM}="
+      newHash = $.urlDecode(location.hash).replace "##{SEARCH_PARAM}=#{value} ", "##{SEARCH_PARAM}="
       app.router.replaceHash(newHash)
       value
 
   getHashValue: ->
-    try (new RegExp "^##{SEARCH_PARAM}=(.+?) .").exec(decodeURIComponent location.hash)?[1] catch
+    try (new RegExp "^##{SEARCH_PARAM}=(.+?) .").exec($.urlDecode location.hash)?[1] catch