diff --git a/lib/server/v2/RequestContext.d.ts b/lib/server/v2/RequestContext.d.ts index d59c3393..503606ac 100644 --- a/lib/server/v2/RequestContext.d.ts +++ b/lib/server/v2/RequestContext.d.ts @@ -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; diff --git a/lib/server/v2/RequestContext.js b/lib/server/v2/RequestContext.js index b995eacb..b96eb715 100644 --- a/lib/server/v2/RequestContext.js +++ b/lib/server/v2/RequestContext.js @@ -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); diff --git a/lib/server/v2/commands/Lock.js b/lib/server/v2/commands/Lock.js index b61bbb56..6405826c 100644 --- a/lib/server/v2/commands/Lock.js +++ b/lib/server/v2/commands/Lock.js @@ -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); diff --git a/lib/server/v2/commands/Propfind.js b/lib/server/v2/commands/Propfind.js index b1ae8a4c..1f9281fa 100644 --- a/lib/server/v2/commands/Propfind.js +++ b/lib/server/v2/commands/Propfind.js @@ -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]; } @@ -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); }); @@ -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); @@ -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); @@ -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); }); }); }); diff --git a/lib/server/v2/commands/Proppatch.js b/lib/server/v2/commands/Proppatch.js index 50c317ba..127f7f48 100644 --- a/lib/server/v2/commands/Proppatch.js +++ b/lib/server/v2/commands/Proppatch.js @@ -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'); diff --git a/src/server/v2/RequestContext.ts b/src/server/v2/RequestContext.ts index b16e47d5..b9ce7bc9 100644 --- a/src/server/v2/RequestContext.ts +++ b/src/server/v2/RequestContext.ts @@ -263,6 +263,11 @@ export class HTTPRequestContext extends RequestContext callback(null, ctx); } } + + static encodeURL(url : string) + { + return encodeURI(url); + } noBodyExpected(callback : () => void) { diff --git a/src/server/v2/commands/Lock.ts b/src/server/v2/commands/Lock.ts index 7e70f350..e62cf528 100644 --- a/src/server/v2/commands/Lock.ts +++ b/src/server/v2/commands/Lock.ts @@ -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); diff --git a/src/server/v2/commands/Propfind.ts b/src/server/v2/commands/Propfind.ts index 6f51e660..69912e66 100644 --- a/src/server/v2/commands/Propfind.ts +++ b/src/server/v2/commands/Propfind.ts @@ -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]; @@ -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); }) @@ -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))) } } @@ -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); @@ -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); })) }) diff --git a/src/server/v2/commands/Proppatch.ts b/src/server/v2/commands/Proppatch.ts index 77c64bb9..85f129cb 100644 --- a/src/server/v2/commands/Proppatch.ts +++ b/src/server/v2/commands/Proppatch.ts @@ -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 {