Skip to content

Commit

Permalink
Fixed the URL encoding on all 'href', 'location' and 'displayname' ta…
Browse files Browse the repository at this point in the history
…gs in the XML responses
  • Loading branch information
AdrienCastex committed Nov 1, 2017
1 parent 75dce6f commit 5d48f22
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions lib/server/v2/RequestContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export declare class HTTPRequestContext extends RequestContext {
exit: () => void;
protected constructor(server: WebDAVServer, request: http.IncomingMessage, response: http.ServerResponse, exit: () => void);
static create(server: WebDAVServer, request: http.IncomingMessage, response: http.ServerResponse, callback: (error: Error, ctx: HTTPRequestContext) => void): void;
static encodeURL(url: string): string;
noBodyExpected(callback: () => void): void;
checkIfHeader(resource: Resource, callback: () => void): any;
checkIfHeader(fs: FileSystem, path: Path, callback: () => void): any;
Expand Down
3 changes: 3 additions & 0 deletions lib/server/v2/RequestContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ var HTTPRequestContext = (function (_super) {
callback(null, ctx);
}
};
HTTPRequestContext.encodeURL = function (url) {
return encodeURI(url);
};
HTTPRequestContext.prototype.noBodyExpected = function (callback) {
if (this.server.options.strictMode && this.headers.contentLength !== 0) {
this.setCode(HTTPCodes_1.HTTPCodes.UnsupportedMediaType);
Expand Down
2 changes: 1 addition & 1 deletion lib/server/v2/commands/Lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createResponse(ctx, lock) {
activelock.ele('D:locktype').ele(lock.lockKind.type.value);
activelock.ele('D:lockscope').ele(lock.lockKind.scope.value);
activelock.ele('D:locktoken').ele('D:href', undefined, true).add(lock.uuid);
activelock.ele('D:lockroot').ele('D:href', undefined, true).add(ctx.fullUri());
activelock.ele('D:lockroot').ele('D:href', undefined, true).add(WebDAVRequest_1.HTTPRequestContext.encodeURL(ctx.fullUri()));
activelock.ele('D:depth').add(lock.depth === -1 ? 'infinity' : lock.depth.toString());
if (lock.owner)
activelock.ele('D:owner').add(lock.owner);
Expand Down
11 changes: 4 additions & 7 deletions lib/server/v2/commands/Propfind.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ function parseRequestBody(ctx, data) {
return allTrue;
}
}
function encode(url) {
return encodeURI(url);
}
function propstatStatus(status) {
return 'HTTP/1.1 ' + status + ' ' + http.STATUS_CODES[status];
}
Expand Down Expand Up @@ -137,7 +134,7 @@ var default_1 = (function () {
resource.fs.getFullPath(ctx, resource.path, function (e, path) {
if (e)
return nbOut(e);
var p = encode(ctx.fullUri(path.toString()));
var p = WebDAVRequest_1.HTTPRequestContext.encodeURL(ctx.fullUri(path.toString()));
response_1.ele('D:href', undefined, true).add(p);
response_1.ele('D:location').ele('D:href', undefined, true).add(p);
});
Expand Down Expand Up @@ -218,7 +215,7 @@ var default_1 = (function () {
activelock.ele('D:owner').add(lock.owner);
activelock.ele('D:timeout').add('Second-' + (lock.expirationDate - Date.now()));
activelock.ele('D:locktoken').ele('D:href', undefined, true).add(lock.uuid);
activelock.ele('D:lockroot').ele('D:href', undefined, true).add(encode(ctx.fullUri(path)));
activelock.ele('D:lockroot').ele('D:href', undefined, true).add(WebDAVRequest_1.HTTPRequestContext.encodeURL(ctx.fullUri(path)));
}
}
nbOut(null);
Expand All @@ -231,7 +228,7 @@ var default_1 = (function () {
resource.fs.getFullPath(ctx, resource.path, function (e, path) {
if (e)
return nbOut(e);
var p = encode(ctx.fullUri(path.toString()));
var p = WebDAVRequest_1.HTTPRequestContext.encodeURL(ctx.fullUri(path.toString()));
var href = p.lastIndexOf('/') !== p.length - 1 && type.isDirectory ? p + '/' : p;
response.ele('D:href', undefined, true).add(href);
response.ele('D:location').ele('D:href', undefined, true).add(p);
Expand Down Expand Up @@ -266,7 +263,7 @@ var default_1 = (function () {
methodDisplayName = resource.displayName;
methodDisplayName.bind(resource)(function (e, name) { return process.nextTick(function () {
if (!e)
tags.displayname.el.add(name ? encode(name) : '');
tags.displayname.el.add(name ? WebDAVRequest_1.HTTPRequestContext.encodeURL(name) : '');
nbOut(e);
}); });
});
Expand Down
2 changes: 1 addition & 1 deletion lib/server/v2/commands/Proppatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var default_1 = (function () {
'xmlns:D': 'DAV:'
});
var response = multistatus.ele('D:response');
response.ele('D:href', undefined, true).add(ctx.fullUri());
response.ele('D:href', undefined, true).add(WebDAVRequest_1.HTTPRequestContext.encodeURL(ctx.fullUri()));
try {
var xml = xml_js_builder_1.XML.parse(data);
var root_1 = xml.find('DAV:propertyupdate');
Expand Down
5 changes: 5 additions & 0 deletions src/server/v2/RequestContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ export class HTTPRequestContext extends RequestContext
callback(null, ctx);
}
}

static encodeURL(url : string)
{
return encodeURI(url);
}

noBodyExpected(callback : () => void)
{
Expand Down
2 changes: 1 addition & 1 deletion src/server/v2/commands/Lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function createResponse(ctx : HTTPRequestContext, lock : Lock)
activelock.ele('D:locktype').ele(lock.lockKind.type.value);
activelock.ele('D:lockscope').ele(lock.lockKind.scope.value);
activelock.ele('D:locktoken').ele('D:href', undefined, true).add(lock.uuid);
activelock.ele('D:lockroot').ele('D:href', undefined, true).add(ctx.fullUri());
activelock.ele('D:lockroot').ele('D:href', undefined, true).add(HTTPRequestContext.encodeURL(ctx.fullUri()));
activelock.ele('D:depth').add(lock.depth === -1 ? 'infinity' : lock.depth.toString());
if(lock.owner)
activelock.ele('D:owner').add(lock.owner);
Expand Down
13 changes: 4 additions & 9 deletions src/server/v2/commands/Propfind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ function parseRequestBody(ctx : HTTPRequestContext, data : Buffer) : PropertyRul
}
}

function encode(url : string)
{
return encodeURI(url);
}

function propstatStatus(status : number)
{
return 'HTTP/1.1 ' + status + ' ' + http.STATUS_CODES[status];
Expand Down Expand Up @@ -187,7 +182,7 @@ export default class implements HTTPMethod
if(e)
return nbOut(e);

const p = encode(ctx.fullUri(path.toString()));
const p = HTTPRequestContext.encodeURL(ctx.fullUri(path.toString()));
response.ele('D:href', undefined, true).add(p);
response.ele('D:location').ele('D:href', undefined, true).add(p);
})
Expand Down Expand Up @@ -292,7 +287,7 @@ export default class implements HTTPMethod
activelock.ele('D:owner').add(lock.owner)
activelock.ele('D:timeout').add('Second-' + (lock.expirationDate - Date.now()))
activelock.ele('D:locktoken').ele('D:href', undefined, true).add(lock.uuid)
activelock.ele('D:lockroot').ele('D:href', undefined, true).add(encode(ctx.fullUri(path)))
activelock.ele('D:lockroot').ele('D:href', undefined, true).add(HTTPRequestContext.encodeURL(ctx.fullUri(path)))
}
}

Expand All @@ -309,7 +304,7 @@ export default class implements HTTPMethod
if(e)
return nbOut(e);

const p = encode(ctx.fullUri(path.toString()));
const p = HTTPRequestContext.encodeURL(ctx.fullUri(path.toString()));
const href = p.lastIndexOf('/') !== p.length - 1 && type.isDirectory ? p + '/' : p;
response.ele('D:href', undefined, true).add(href);
response.ele('D:location').ele('D:href', undefined, true).add(p);
Expand Down Expand Up @@ -355,7 +350,7 @@ export default class implements HTTPMethod

methodDisplayName.bind(resource)((e, name) => process.nextTick(() => {
if(!e)
tags.displayname.el.add(name ? encode(name) : '');
tags.displayname.el.add(name ? HTTPRequestContext.encodeURL(name) : '');
nbOut(e);
}))
})
Expand Down
2 changes: 1 addition & 1 deletion src/server/v2/commands/Proppatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class implements HTTPMethod
'xmlns:D': 'DAV:'
});
const response = multistatus.ele('D:response');
response.ele('D:href', undefined, true).add(ctx.fullUri());
response.ele('D:href', undefined, true).add(HTTPRequestContext.encodeURL(ctx.fullUri()));

try
{
Expand Down

0 comments on commit 5d48f22

Please sign in to comment.