From 49296b514ba03f6ed5f84fbe3e63e874bb1e4b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 14 Oct 2014 15:22:31 +0200 Subject: [PATCH] domain_parser must escape when quoting '"' issue4247 review7651002 --- src/common.js | 3 +++ tests/sao.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/common.js b/src/common.js index 007da413a6..fb5449b667 100644 --- a/src/common.js +++ b/src/common.js @@ -1003,6 +1003,9 @@ if (typeof value != 'string') { return value; } + if (value.contains('"')) { + value = value.replace(new RegExp('"', 'g'), '\\"'); + } var tests = [':', ' ', '(', ')'].concat(this.OPERATORS); for (var i = 0; i < tests.length; i++) { var test = tests[i]; diff --git a/tests/sao.js b/tests/sao.js index c1ce397b4d..47c3830d8b 100644 --- a/tests/sao.js +++ b/tests/sao.js @@ -919,6 +919,9 @@ ['Name: = Name: Doe', [ ['Name', '=', null], ['Name', null, 'Doe'] + ]], + ['Name: \\"foo\\"', [ + ['Name', null, '"foo"'] ]] ].forEach(function(test) { var value = test[0]; @@ -966,6 +969,21 @@ }); }); + QUnit.test('DomainParser.quote', function() { + var parser = new Sao.common.DomainParser(); + + [ + ['test', 'test'], + ['foo bar', '"foo bar"'], + ['"foo"', '\\\"foo\\\"'] + ].forEach(function(test) { + var value = test[0]; + var result = test[1]; + QUnit.ok(Sao.common.compare(parser.quote(value), result), + 'quote(' + JSON.stringify(value) + ')'); + }); + }); + QUnit.test('DomainParser.split_target_value', function() { var parser = new Sao.common.DomainParser();