Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
solr-frontend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
1107153b
authored
2016-11-17 16:44:04 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Quote and unquote url parameters, to handle funky chars.
1 parent
0a87101c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
4 deletions
src/scripts/solr/model/Solr.js
src/scripts/solr/model/Solr.js
View file @
1107153
...
...
@@ -11,6 +11,20 @@ define(function(require) {
//var module = require('module');
function
unquoteUrlValue
(
value
)
{
value
=
value
.
replace
(
/
\+
/g
,
' '
);
value
=
value
.
replace
(
/%
([
0-9a-fA-F
]{2})
/g
,
function
(
match
,
hexValue
)
{
return
String
.
fromCharCode
(
parseInt
(
hexValue
,
16
));
});
return
value
;
}
function
quoteUrlValue
(
value
)
{
// RFC-3986 reserves these chars
return
encodeURIComponent
(
value
).
replace
(
/
[
!'()*
]
/g
,
function
(
c
)
{
return
'%'
+
c
.
charCodeAt
(
0
).
toString
(
16
);
});
}
var
QueryTextFields
=
Backbone
.
Model
.
extend
({
initialize
:
function
(
data
,
options
)
{
},
...
...
@@ -76,8 +90,7 @@ define(function(require) {
if
(
keyFieldValue
)
{
var
key
=
keyFieldValue
[
1
];
var
field
=
keyFieldValue
[
2
];
var
value
=
keyFieldValue
[
3
];
value
=
value
.
replace
(
/
(\+
|%20
)
/g
,
' '
);
var
value
=
unquoteUrlValue
(
keyFieldValue
[
3
]);
var
impl
=
formNameMap
[
key
];
if
(
impl
)
{
if
(
impl
instanceof
QueryTextField
)
{
...
...
@@ -135,10 +148,10 @@ define(function(require) {
var
serializedQuery
=
_
.
map
(
result
,
function
(
value
,
key
)
{
if
(
_
.
isArray
(
value
))
{
return
_
.
map
(
value
,
function
(
item
,
index
)
{
return
key
+
'='
+
item
;
return
key
+
'='
+
quoteUrlValue
(
item
)
;
}).
join
(
'&'
);
}
else
{
return
key
+
'='
+
value
;
return
key
+
'='
+
quoteUrlValue
(
value
)
;
}
}).
join
(
'&'
);
this
.
set
(
'serializedQuery'
,
serializedQuery
);
...
...
Please
register
or
sign in
to post a comment