Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AB65E176E9 for ; Mon, 6 Oct 2014 17:27:25 +0000 (UTC) Received: (qmail 77245 invoked by uid 500); 6 Oct 2014 17:27:25 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 77190 invoked by uid 500); 6 Oct 2014 17:27:25 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 77181 invoked by uid 99); 6 Oct 2014 17:27:25 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Oct 2014 17:27:25 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 420CE320969; Mon, 6 Oct 2014 17:27:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: robertkowalski@apache.org To: commits@couchdb.apache.org Date: Mon, 06 Oct 2014 17:27:25 -0000 Message-Id: <882506846a1f459eaf69c8d726a8cfa0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] fauxton commit: updated refs/heads/master to 92964af 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 Authored: Mon Oct 6 09:48:13 2014 +0200 Committer: Robert Kowalski 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; } };