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)

x86_64
Windows 8
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla27

People

(Reporter: bbenvie, Assigned: bbenvie)

Details

Attachments

(1 file, 1 obsolete file)

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
Attached patch bug-919769.patch (obsolete) — Splinter Review
Assignee: nobody → bbenvie
Status: NEW → ASSIGNED
Attachment #808833 - Flags: review?(dteller)
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+
(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?
(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?
Attached patch bug-919769.patchSplinter Review
Don't convert forward slashes if the path begins with two backslashes.
Attachment #808833 - Attachment is obsolete: true
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+
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → mozilla27
Product: Toolkit → Toolkit Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: