Skip to content
This repository was archived by the owner on Jan 28, 2019. It is now read-only.

Commit 45c4dc2

Browse files
committed
Merge pull request #71 from medic/1147-exists-validation-unicode-fix
modified validation lib to better support unicode query values.
2 parents f679dec + ab0ce81 commit 45c4dc2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/validation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ var _exists = function(doc, query, callback) {
3232
};
3333

3434
var _formatParam = function(name, value) {
35-
return encodeURIComponent(name) + ':"' + encodeURIComponent(value) + '"';
35+
name = name.replace(/"/g, '');
36+
value = value.replace(/"/g, '\\"');
37+
return name + ':"' + value + '"';
3638
};
3739

3840
module.exports = {
41+
_formatParam: _formatParam,
3942
extractErrors: function(result, messages, ignores) {
4043
// wrap single item in array; defaults to empty array
4144
ignores = ignores || [];

test/unit/validations.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,27 @@ exports['pass uniqueWithin validation on old doc'] = function(test) {
244244
});
245245
};
246246

247+
exports['formatParam does not encode unicode'] = function(test) {
248+
test.same(validation._formatParam('form', 'द'), 'form:"द"');
249+
test.done();
250+
};
251+
252+
exports['formatParam escapes quotes in values'] = function(test) {
253+
test.same(
254+
validation._formatParam('form', ' " AND everything'),
255+
'form:" \\" AND everything"'
256+
);
257+
test.done();
258+
};
259+
260+
exports['formatParam rejects quotes in field names'] = function(test) {
261+
test.same(
262+
validation._formatParam('*:"everything', 'xyz'),
263+
'*:everything:"xyz"'
264+
);
265+
test.done();
266+
};
267+
247268
exports['pass exists validation when matching document'] = function(test) {
248269
test.expect(2);
249270
// simulate view results with doc attribute

0 commit comments

Comments
 (0)