Skip to content

Commit 57ef303

Browse files
Vincent Petrydanxuliu
authored andcommitted
Properly decode id from URI
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>
1 parent ee322ba commit 57ef303

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

core/js/oc-backbone-webdav.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
// so we take the part before that
129129
} while (!result && parts.length > 0);
130130

131-
return result;
131+
return decodeURIComponent(result);
132132
}
133133

134134
function isSuccessStatus(status) {

core/js/tests/specs/oc-backbone-webdavSpec.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ describe('Backbone Webdav extension', function() {
229229
'married': '{http://owncloud.org/ns}married', // bool
230230
},
231231
url: function() {
232-
return 'http://example.com/owncloud/remote.php/test/' + this.id;
232+
return 'http://example.com/owncloud/remote.php/test/' + encodeURIComponent(this.id);
233233
},
234234
parse: function(data) {
235235
return {
@@ -394,7 +394,7 @@ describe('Backbone Webdav extension', function() {
394394
beforeEach(function() {
395395
NodeModel = OC.Backbone.WebdavNode.extend({
396396
url: function() {
397-
return 'http://example.com/owncloud/remote.php/dav/endpoint/nodemodel/' + this.id;
397+
return 'http://example.com/owncloud/remote.php/dav/endpoint/nodemodel/' + encodeURIComponent(this.id);
398398
},
399399
davProperties: {
400400
'firstName': '{http://owncloud.org/ns}first-name',
@@ -547,7 +547,7 @@ describe('Backbone Webdav extension', function() {
547547
beforeEach(function() {
548548
ChildModel = OC.Backbone.WebdavNode.extend({
549549
url: function() {
550-
return 'http://example.com/owncloud/remote.php/dav/davcol/' + this.id;
550+
return 'http://example.com/owncloud/remote.php/dav/davcol/' + encodeURIComponent(this.id);
551551
},
552552
davProperties: {
553553
'firstName': '{http://owncloud.org/ns}first-name',
@@ -561,7 +561,7 @@ describe('Backbone Webdav extension', function() {
561561
NodeModel = OC.Backbone.WebdavCollectionNode.extend({
562562
childrenCollectionClass: ChildrenCollection,
563563
url: function() {
564-
return 'http://example.com/owncloud/remote.php/dav/' + this.id;
564+
return 'http://example.com/owncloud/remote.php/dav/' + encodeURIComponent(this.id);
565565
},
566566
davProperties: {
567567
'firstName': '{http://owncloud.org/ns}first-name',
@@ -649,6 +649,42 @@ describe('Backbone Webdav extension', function() {
649649
expect(collection.at(1).isNew()).toEqual(false);
650650
});
651651

652+
it('parses id from href if no id was queried', function() {
653+
var model = new NodeModel({
654+
id: 'davcol'
655+
});
656+
657+
var collection = model.getChildrenCollection();
658+
collection.fetch();
659+
660+
deferredRequest.resolve({
661+
status: 207,
662+
body: [
663+
// root element
664+
{
665+
href: 'http://example.com/owncloud/remote.php/dav/davcol/',
666+
propStat: []
667+
},
668+
// first model
669+
{
670+
href: 'http://example.com/owncloud/remote.php/dav/davcol/sub%40thing',
671+
propStat: [{
672+
status: 'HTTP/1.1 200 OK',
673+
properties: {
674+
'{http://owncloud.org/ns}first-name': 'Hello',
675+
'{http://owncloud.org/ns}last-name': 'World'
676+
}
677+
}]
678+
}
679+
]
680+
});
681+
682+
expect(collection.length).toEqual(1);
683+
684+
expect(collection.at(0).id).toEqual('sub@thing');
685+
expect(collection.at(0).url()).toEqual('http://example.com/owncloud/remote.php/dav/davcol/sub%40thing');
686+
});
687+
652688
it('creates the Webdav collection with MKCOL', function() {
653689
var model = new NodeModel({
654690
id: 'davcol'

0 commit comments

Comments
 (0)