Skip to content

Commit

Permalink
Properly decode id from URI
Browse files Browse the repository at this point in the history
When parsing an href to get the id of a WebdavNode, make sure to also
decode it.

(cherry picked from commit d2e45321e8f7586f3086d7e521aeb887aa2d06b6)
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
Vincent Petry authored and danxuliu committed Jun 25, 2017
1 parent ee322ba commit 57ef303
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/js/oc-backbone-webdav.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
// so we take the part before that
} while (!result && parts.length > 0);

return result;
return decodeURIComponent(result);
}

function isSuccessStatus(status) {
Expand Down
44 changes: 40 additions & 4 deletions core/js/tests/specs/oc-backbone-webdavSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('Backbone Webdav extension', function() {
'married': '{http://owncloud.org/ns}married', // bool
},
url: function() {
return 'http://example.com/owncloud/remote.php/test/' + this.id;
return 'http://example.com/owncloud/remote.php/test/' + encodeURIComponent(this.id);
},
parse: function(data) {
return {
Expand Down Expand Up @@ -394,7 +394,7 @@ describe('Backbone Webdav extension', function() {
beforeEach(function() {
NodeModel = OC.Backbone.WebdavNode.extend({
url: function() {
return 'http://example.com/owncloud/remote.php/dav/endpoint/nodemodel/' + this.id;
return 'http://example.com/owncloud/remote.php/dav/endpoint/nodemodel/' + encodeURIComponent(this.id);
},
davProperties: {
'firstName': '{http://owncloud.org/ns}first-name',
Expand Down Expand Up @@ -547,7 +547,7 @@ describe('Backbone Webdav extension', function() {
beforeEach(function() {
ChildModel = OC.Backbone.WebdavNode.extend({
url: function() {
return 'http://example.com/owncloud/remote.php/dav/davcol/' + this.id;
return 'http://example.com/owncloud/remote.php/dav/davcol/' + encodeURIComponent(this.id);
},
davProperties: {
'firstName': '{http://owncloud.org/ns}first-name',
Expand All @@ -561,7 +561,7 @@ describe('Backbone Webdav extension', function() {
NodeModel = OC.Backbone.WebdavCollectionNode.extend({
childrenCollectionClass: ChildrenCollection,
url: function() {
return 'http://example.com/owncloud/remote.php/dav/' + this.id;
return 'http://example.com/owncloud/remote.php/dav/' + encodeURIComponent(this.id);
},
davProperties: {
'firstName': '{http://owncloud.org/ns}first-name',
Expand Down Expand Up @@ -649,6 +649,42 @@ describe('Backbone Webdav extension', function() {
expect(collection.at(1).isNew()).toEqual(false);
});

it('parses id from href if no id was queried', function() {
var model = new NodeModel({
id: 'davcol'
});

var collection = model.getChildrenCollection();
collection.fetch();

deferredRequest.resolve({
status: 207,
body: [
// root element
{
href: 'http://example.com/owncloud/remote.php/dav/davcol/',
propStat: []
},
// first model
{
href: 'http://example.com/owncloud/remote.php/dav/davcol/sub%40thing',
propStat: [{
status: 'HTTP/1.1 200 OK',
properties: {
'{http://owncloud.org/ns}first-name': 'Hello',
'{http://owncloud.org/ns}last-name': 'World'
}
}]
}
]
});

expect(collection.length).toEqual(1);

expect(collection.at(0).id).toEqual('sub@thing');
expect(collection.at(0).url()).toEqual('http://example.com/owncloud/remote.php/dav/davcol/sub%40thing');
});

it('creates the Webdav collection with MKCOL', function() {
var model = new NodeModel({
id: 'davcol'
Expand Down

0 comments on commit 57ef303

Please sign in to comment.