Closed
Bug 919769
Opened 12 years ago
Closed 12 years ago
OS.Path.normalize doesn't handle forward slashes correctly on Windows
Categories
(Toolkit Graveyard :: OS.File, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
mozilla27
People
(Reporter: bbenvie, Assigned: bbenvie)
Details
Attachments
(1 file, 1 obsolete file)
|
3.17 KB,
patch
|
Yoric
:
review+
|
Details | Diff | Splinter Review |
The Windows version of OS.Path.normalize has a couple problems with handling forward slashes.
First, it only replaces the first forward slash with a back slash.
> OS.Path.normalize("a/b/c")
> > a\b/c
Second, it strips out the forward slash if it comes after the drive and doesn't replace it with a backslash.
> OS.Path.normalize("c:/a")
> > c:a
| Assignee | ||
Comment 1•12 years ago
|
||
Assignee: nobody → bbenvie
Status: NEW → ASSIGNED
| Assignee | ||
Updated•12 years ago
|
Attachment #808833 -
Flags: review?(dteller)
Comment 2•12 years ago
|
||
Comment on attachment 808833 [details] [diff] [review]
bug-919769.patch
Review of attachment 808833 [details] [diff] [review]:
-----------------------------------------------------------------
::: toolkit/components/osfile/modules/ospath_win.jsm
@@ +214,5 @@
> let normalize = function(path) {
> let stack = [];
>
> + // Normalize "/" to "\\"
> + path = path.replace(/\//g, "\\");
That's better, but doing things here will introduce another error if we have a path that looks like
\\foo/a/b/c/d
in this case, the forward slash is a legal character inside a file name and "foo/a/b/c/d" should not be converted to "foo\\a\\b\\c\\d".
I believe it is sufficient to perform that transformation only if |path| doesn't start with "\\".
::: toolkit/components/osfile/tests/xpcshell/test_path.js
@@ +101,5 @@
> + do_check_eq(Win.normalize("c:////a/b/c"), "c:\\a\\b\\c");
> + do_check_eq(Win.normalize("c:/a/b/c///"), "c:\\a\\b\\c");
> + do_check_eq(Win.normalize("c:/a/b/c/../../../d/e/f"), "c:\\d\\e\\f");
> + do_check_eq(Win.normalize("c:a/b/c/../../../d/e/f"), "c:d\\e\\f");
> +
Could you also add the basename, winGetDrive, etc. tests here?
Attachment #808833 -
Flags: review?(dteller) → feedback+
| Assignee | ||
Comment 3•12 years ago
|
||
(In reply to David Rajchenbach Teller [:Yoric] from comment #2)
> Could you also add the basename, winGetDrive, etc. tests here?
None of those currently handle forward slashes at all. The uses I've seen involve first using normalize on a path and then feeding it into those. Should I make them handle forward slashes?
| Assignee | ||
Comment 4•12 years ago
|
||
(In reply to David Rajchenbach Teller [:Yoric] from comment #2)
> I believe it is sufficient to perform that transformation only if |path|
> doesn't start with "\\".
Do you mean one or two backslashes? As in, is that escaped already or not?
| Assignee | ||
Comment 5•12 years ago
|
||
Don't convert forward slashes if the path begins with two backslashes.
Attachment #808833 -
Attachment is obsolete: true
Comment 6•12 years ago
|
||
Comment on attachment 809343 [details] [diff] [review]
bug-919769.patch
Review of attachment 809343 [details] [diff] [review]:
-----------------------------------------------------------------
You correctly inferred that I meant "\\\\".
Also, you are right, let's not add tests for winGetDrive, etc.
Attachment #809343 -
Flags: review+
| Assignee | ||
Comment 7•12 years ago
|
||
Whiteboard: [fixed-in-fx-team]
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → mozilla27
Updated•2 years ago
|
Product: Toolkit → Toolkit Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•