Repository: couchdb-fauxton Updated Branches: refs/heads/master eff09ef45 -> 92964af8e
Url-encode document-ids properly - modify the helper to also urlencode on `%` Closes COUCHDB-2342 Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/92964af8 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/92964af8 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/92964af8 Branch: refs/heads/master Commit: 92964af8ee93c53677b8abaea9463fd9ae7a4d7f Parents: 1d79b3e Author: Robert Kowalski <[email protected]> Authored: Mon Oct 6 09:48:13 2014 +0200 Committer: Robert Kowalski <[email protected]> Committed: Mon Oct 6 19:27:09 2014 +0200 ---------------------------------------------------------------------- app/addons/documents/views-doceditor.js | 3 ++- app/core/tests/utilsSpec.js | 27 +++++++++++++++++++++++++++ app/core/utils.js | 9 +++++---- 3 files changed, 34 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/92964af8/app/addons/documents/views-doceditor.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/views-doceditor.js b/app/addons/documents/views-doceditor.js index bd15596..7de0be8 100644 --- a/app/addons/documents/views-doceditor.js +++ b/app/addons/documents/views-doceditor.js @@ -386,7 +386,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, resizeColumns, prett this.model.save().then(function () { editor.editSaved(); - FauxtonAPI.navigate('/database/' + that.database.safeID() + '/' + that.model.id); + FauxtonAPI.navigate('/database/' + that.database.safeID() + '/' + app.utils.safeURLName(that.model.id)); }).fail(function(xhr) { var responseText = JSON.parse(xhr.responseText).reason; FauxtonAPI.addNotification({ @@ -423,6 +423,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, resizeColumns, prett } json = JSON.parse(this.editor.getValue()); + json._id = app.utils.safeURLName(json._id); this.model.clear().set(json, {validate: true}); if (this.model.validationError) { http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/92964af8/app/core/tests/utilsSpec.js ---------------------------------------------------------------------- diff --git a/app/core/tests/utilsSpec.js b/app/core/tests/utilsSpec.js new file mode 100644 index 0000000..2629699 --- /dev/null +++ b/app/core/tests/utilsSpec.js @@ -0,0 +1,27 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +define([ + "app", + "testUtils" +], function (app, testUtils) { + var assert = testUtils.assert; + + describe("utils", function () { + describe("safeURLName", function () { + it("should encode urls with a % (COUCHDB-2342)", function () { + var res = app.utils.safeURLName("design%20foo"); + assert.equal(res, "design%2520foo"); + }); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/92964af8/app/core/utils.js ---------------------------------------------------------------------- diff --git a/app/core/utils.js b/app/core/utils.js index cc8b02a..9c4fb39 100644 --- a/app/core/utils.js +++ b/app/core/utils.js @@ -82,10 +82,11 @@ function ($, _) { return name.replace(/[^\w\s]/gi,""); }, - safeURLName: function(name){ - var testName = name || ""; - var checkforBad = testName.match(/[\$\-/,+-]/g); - return (checkforBad !== null)?encodeURIComponent(name):name; + safeURLName: function (name) { + var testName = name || "", + hasBadChar = /[\$\-/%,+-]/g.test(testName); + + return hasBadChar ? encodeURIComponent(name) : name; } };
