jsDAV icon indicating copy to clipboard operation
jsDAV copied to clipboard

Unterminated character class

Open redrockzee opened this issue 8 years ago • 1 comments

This is my file server startup.
: var jsDAV = require("jsDAV"); jsDAV.debugMode = true; var jsDAV_Locks_Backend_FS = require("jsDAV/lib/DAV/plugins/locks/fs");

jsDAV.createServer({ node: "./webdav", locksBackend: jsDAV_Locks_Backend_FS.new("./webdav") }, 8889);

I get this error when performing a GET on a docx file on Windows. Is the Windows path the problem?

[error] [SyntaxError: Invalid regular expression: /[]+$/: Unterminated character class] SyntaxError: Invalid regular expression: /[]+$/: Unterminated character class at new RegExp (native) at Object.exports.rtrim (c:\devel\dov\node_modules\jsDAV\lib\shared\util.js:114:14) at Object.module.exports.jsDAV_Tree.extend.getRealPath (c:\devel\dov\node_modules\jsDAV\lib\DAV\backends\fs\tree.js:62:31) at Object.module.exports.jsDAV_Tree.extend.getNodeForPath (c:\devel\dov\node_modules\jsDAV\lib\DAV\backends\fs\tree.js:41:29) at __dirname.getNodeForPath (c:\devel\dov\node_modules\jsDAV\lib\DAV\handler.js:328:26) at __dirname.getAllowedMethods (c:\devel\dov\node_modules\jsDAV\lib\DAV\handler.js:1199:14) at __dirname.httpOptions (c:\devel\dov\node_modules\jsDAV\lib\DAV\handler.js:374:14) at c:\devel\dov\node_modules\jsDAV\lib\DAV\handler.js:250:81 at c:\devel\dov\node_modules\jsDAV\lib\shared\asyncEvents.js:82:13 at handler (c:\devel\dov\node_modules\asyncjs\lib\async.js:371:33)

This code throws the error: /**

  • Removes trailing whitespace
  • version: 1107.2516
  • from: http://phpjs.org/functions/rtrim
  • original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  • example 1: rtrim('    Kevin van Zonneveld    ');
    
  • returns 1: '    Kevin van Zonneveld'
    
    _/ exports.rtrim = function(str, charlist) { charlist = !charlist ? " \s\u00A0" : (charlist+"").replace(/([.?/_{}+$^:])/g, "$1"); var re = new RegExp("[" + charlist + "]+$", "g"); return (str+"").replace(re, ""); };

redrockzee avatar Aug 24 '16 17:08 redrockzee

I fixed this by replacing this function so that it trims both / and \ rather than just using Path.sep. Path.sep contains \ on Windows and is not escaped properly for regular expressions in rtrim().

In tree.js: getRealPath: function(publicPath) { //return Path.join(Util.rtrim(this.basePath, Path.sep), Util.trim(publicPath, Path.sep)); return Path.join(Util.rtrim(this.basePath, '/\'), Util.trim(publicPath, '/\')); },

redrockzee avatar Aug 24 '16 21:08 redrockzee