Open Bug 876681 Opened 13 years ago Updated 5 months ago

Trying to create a profile with a space at the end shows an XPCOM Error

Categories

(Firefox :: General, defect)

x86_64
Windows 7
defect

Tracking

()

REOPENED

People

(Reporter: mkaply, Unassigned)

Details

If you try to create a profile with a space at the end, you get this error: Profile couldn't be created. Probably the chosen folder isn't writable. [Exception... "Component returned failure code: 0x80520008 (NS_ERROR_FILE_ALREADY_EXISTS) [nsIToolkitProfileService.createProfile]" nsresult: "0x80520008 (NS_ERROR_FILE_ALREADY_EXISTS)" location: "JS frame :: chrome://mozapps/content/profile/createProfileWizard.js :: onFinish :: line 196" data: no] You should get a more readable error.
Per policy at https://wiki.mozilla.org/Bug_Triage/Projects/Bug_Handling/Bug_Husbandry#Inactive_Bugs. If this bug is not an enhancement request or a bug not present in a supported release of Firefox, then it may be reopened.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → INACTIVE
Status: RESOLVED → REOPENED
Resolution: INACTIVE → ---
Severity: normal → S3

Still reproduces on current trunk, though the underlying XPCOM error has shifted from NS_ERROR_FILE_ALREADY_EXISTS (original report) to NS_ERROR_FILE_NOT_FOUND. The root cause is unchanged: on Windows, NTFS silently strips trailing spaces (and dots) from directory names at create time, so the salted profile directory ends up on disk without the trailing whitespace while the wizard's bookkeeping still references the original name. Whichever subsequent step looks for the name-as-typed throws, and the raw exception text is shown to the user via Services.prompt.alert in onFinish.

The cleanest fix is to reject the invalid name at validation time so it never reaches createProfile. No new strings required — the existing invalidChar string can be reused with the offending whitespace character as the format argument, which gives a sensible message (The character " " is not allowed in profile names. Please choose a different name.) and disables the Finish button until the user corrects it.

Patch against toolkit/profile/content/createProfileWizard.js:

@@ -207,11 +207,23 @@ function updateProfileName(aNewName) {
 // Checks whether the given string is a valid profile name.
 // Returns an error message describing the error in the name or "" when it's valid.
 function checkProfileName(profileNameToCheck) {
   // Check for emtpy profile name.
   if (!/\S/.test(profileNameToCheck)) {
     return gProfileManagerBundle.getString("profileNameEmpty");
   }
 
+  // Reject leading/trailing whitespace. Windows silently strips trailing
+  // spaces (and dots) from directory names, which desyncs the wizard's
+  // bookkeeping from what's actually on disk and surfaces later as a raw
+  // XPCOM error to the user (bug 876681).
+  let trimmed = profileNameToCheck.trim();
+  if (trimmed !== profileNameToCheck) {
+    let badChar = profileNameToCheck.startsWith(trimmed)
+      ? profileNameToCheck[profileNameToCheck.length - 1]
+      : profileNameToCheck[0];
+    return gProfileManagerBundle.getFormattedString("invalidChar", [badChar]);
+  }
+
   // Check whether all characters in the profile name are allowed.
   if (/([\\*:?<>|\/\"])/.test(profileNameToCheck)) {
     return gProfileManagerBundle.getFormattedString("invalidChar", [RegExp.$1]);
   }

Untaken — happy to hand off, or revisit when I have a cycle.

You need to log in before you can comment on or make changes to this bug.