Closed Bug 745466 Opened 12 years ago Closed 12 years ago

initWithPath fails for "~"

Categories

(Core :: XPCOM, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla14

People

(Reporter: asaf, Assigned: asaf)

Details

Attachments

(1 file)

initWithPath("~/Downloads") - works.
initWithPath("~/Downloads/") - works.
initWithPath("~/") - works.
initWithPath("~") - does not work.
Attached patch patch + testSplinter Review
Assignee: nobody → mano
Status: NEW → ASSIGNED
Attachment #615066 - Flags: superreview?(bzbarsky)
Attachment #615066 - Flags: review?(bzbarsky)
This is necessary for bug 710259 (for importing the Downloads folder if it's set to the user's home folder).
Comment on attachment 615066 [details] [diff] [review]
patch + test

r=me, but this needs a separate sr
Attachment #615066 - Flags: superreview?(bzbarsky)
Attachment #615066 - Flags: superreview?(benjamin)
Attachment #615066 - Flags: review?(bzbarsky)
Attachment #615066 - Flags: review+
Comment on attachment 615066 [details] [diff] [review]
patch + test

Thanks Boris.

>-    if (Substring(filePath, 0, 2).EqualsLiteral("~/")) {
>+    if (filePath.Equals("~") || Substring(filePath, 0, 2).EqualsLiteral("~/")) {
>         nsCOMPtr<nsIFile> homeDir;
>         nsCAutoString homePath;
>         if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_HOME_DIR,
>                                              getter_AddRefs(homeDir))) ||
>             NS_FAILED(homeDir->GetNativePath(homePath))) {
>             return NS_ERROR_FAILURE;
>         }
>-        
>-        mPath = homePath + Substring(filePath, 1, filePath.Length() - 1);
>+ 
>+        mPath = homePath;
>+        if (filePath.Length() > 1)
>+          mPath.Append(Substring(filePath, 1, filePath.Length() - 1));
>     } else {


That shoukd have been > 2 (or could have been, it does not hurt as it is now).
Attachment #615066 - Flags: superreview?(benjamin) → superreview+
http://hg.mozilla.org/integration/mozilla-inbound/rev/0d48714f4773
Target Milestone: --- → mozilla14
https://hg.mozilla.org/mozilla-central/rev/0d48714f4773
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: