Skip to content
Browse files

Fix for bem server on windows (reference #211)

Conflicts:
	npm-shrinkwrap.json
  • Loading branch information...
2 parents ad8fffc + 00f3f27 commit 5d3c94ca6ae98b50ae5e010c63edd3ff6175a3d1 @scf2k scf2k committed Feb 14, 2013
Showing with 62 additions and 3 deletions.
  1. +5 −0 ChangeLog.md
  2. +2 −0 lib/base-server.js
  3. +1 −1 lib/nodes/lib.js
  4. +52 −0 lib/path.js
  5. +1 −1 npm-shrinkwrap.json
  6. +1 −1 package.json
View
5 ChangeLog.md
@@ -1,5 +1,10 @@
bem-tools changelog
===================
+14.02.2013, Version 0.5.25 (stable)
+-----------------------------------
+
+- bem server: windows fixes
+
04.02.2013, Version 0.5.24 (stable)
-----------------------------------
View
2 lib/base-server.js
@@ -150,6 +150,8 @@ exports.Server = INHERIT({
relPath = QS.unescape(reqPath).replace(/^\/|\/$/g, ''),
fullPath = PATH.join(root, relPath);
+ if (PATH.dirSep === '\\') relPath = PATH.unixToOs(relPath);
+
LOGGER.fverbose('*** trying to access %s', fullPath);
// try to find node in arch
View
2 lib/nodes/lib.js
@@ -465,6 +465,6 @@ registry.decl(SvnLibraryNodeName, ScmLibraryNodeName, /** @lends SvnLibraryNode.
function joinUrlPath(url, part) {
var p = URL.parse(url);
- p.pathname = PATH.join(p.pathname, part);
+ p.pathname = PATH.joinPosix(p.pathname, part);
return URL.format(p);
}
View
52 lib/path.js
@@ -44,6 +44,58 @@ exports.unixToOs = function(path) {
return path.replace(/\//g, dirSep);
};
+exports.joinPosix = function() {
+ var paths = Array.prototype.slice.call(arguments, 0);
+ return exports.normalizePosix(paths.filter(function(p, index) {
+ return p && typeof p === 'string';
+ }).join('/'));
+};
+
+exports.normalizePosix = function(path) {
+ var isAbsolute = path.charAt(0) === '/',
+ trailingSlash = path.slice(-1) === '/';
+
+ // Normalize the path
+ path = normalizeArray(path.split('/').filter(function(p) {
+ return !!p;
+ }), !isAbsolute).join('/');
+
+ if (!path && !isAbsolute) {
+ path = '.';
+ }
+ if (path && trailingSlash) {
+ path += '/';
+ }
+
+ return (isAbsolute ? '/' : '') + path;
+};
+
// Support compatability with node 0.6.x and remove warnings on node 0.8.x
exports.exists = FS.exists || PATH.exists;
exports.existsSync = FS.existsSync || PATH.existsSync;
+
+function normalizeArray(parts, allowAboveRoot) {
+ // if the path tries to go above the root, `up` ends up > 0
+ var up = 0;
+ for (var i = parts.length - 1; i >= 0; i--) {
+ var last = parts[i];
+ if (last == '.') {
+ parts.splice(i, 1);
+ } else if (last === '..') {
+ parts.splice(i, 1);
+ up++;
+ } else if (up) {
+ parts.splice(i, 1);
+ up--;
+ }
+ }
+
+ // if the path is allowed to go above the root, restore leading ..s
+ if (allowAboveRoot) {
+ for (; up--; up) {
+ parts.unshift('..');
+ }
+ }
+
+ return parts;
+}
View
2 npm-shrinkwrap.json
@@ -1,6 +1,6 @@
{
"name": "bem",
- "version": "0.5.24",
+ "version": "0.5.25",
"dependencies": {
"coa": {
"version": "0.3.9"
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "bem",
"description": "BEM Tools",
- "version": "0.5.24",
+ "version": "0.5.25",
"homepage": "http://github.com/bem/bem-tools",
"author": "Sergey Berezhnoy <veged@mail.ru> (http://github.com/veged)",
"maintainers": [

0 comments on commit 5d3c94c

Please sign in to comment.
Something went wrong with that request. Please try again.