Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping problem #16

Open
yckart opened this issue Dec 3, 2014 · 4 comments
Open

Escaping problem #16

yckart opened this issue Dec 3, 2014 · 4 comments
Labels

Comments

@yckart
Copy link

yckart commented Dec 3, 2014

Referencing a module with NodeRequirer will end in a "slash" / "backslash" mixed filepath. Don't know if this issue is tackled due my brain...

In the *.sublime-project file, I made the "path" absolute (works well in st):

{
  "folders": [{
    "follow_symlinks": true,
    "path": "d:/path/to/my/awesome/project"
  }]
}

The result looks like something like this:

var emitter = require("./..\..\src\scripts\lib\emitter");

Any ideas how we could resolve this issue?

@megawac
Copy link
Collaborator

megawac commented Dec 3, 2014

Call a path.normpath(path) before placing it in a template?

@yckart
Copy link
Author

yckart commented Dec 3, 2014

@megawac Wow, faster than "speed ​​of light"! 👍

My python knowledge is really restricted. To fix this issue by myself, I have to dive a bit deeper into the matter. ;)

@megawac
Copy link
Collaborator

megawac commented Dec 3, 2014

Hehe, good catch try adding that line to https://github.com/ganemone/NodeRequirer/blob/master/Require.py#L128 and testing if that fixes it for you and send a pr. I can't test it at the moment

@ganemone ganemone added the bug label Feb 21, 2015
@dantman
Copy link
Contributor

dantman commented Mar 5, 2015

(Testing on osx) ntpath.normpath (os.path on Windows) converts \ -> / and posixpath does not do the reverse. I'm not sure what os.path.normpath would fix. That's what I'd use to fix './foo/../bar'.

Right now the code replaces os.sep with '/' when os.sep is not '/'.

Tangentially, I think the more ideal way to reformat the path instead would be something like this and then to use posixpath once we've escaped the paths that actually refer to files.

path_parts = []
path = os.path.normpath(module_path)
while path:
    path, tail = os.path.split(path)
    path_parts.insert(0, tail)

module_path = posixpath.join(*path_parts)

But anyways, since I see the os.sep -> '/' in the code, does this bug still occur?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants