Opened 12 years ago
Closed 12 years ago
#20392 closed defect (bug) (fixed)
user-profile.js causing Javascript error in user-new.php
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.4 | Priority: | normal |
Severity: | normal | Version: | 3.3.1 |
Component: | Users | Keywords: | 2nd-opinion |
Focuses: | Cc: |
Description
Line 53 of user-profile.dev.js is causing a Javascript error in user-new.php.
The problem is a result of the fact that user-new.php does NOT include include a "nickname" field. Hence, Line 40 results in inputs['display_nickname']
being undefined...and as a result Line 53
var val = value.replace(/<\/?[a-z][^>]*>/gi, '');
causes a JS error since value
is undefined when id == 'display_nickname'
.
I can think of at least 3 possible fixes:
- add a "nickname" field to user-new.php
- replace Line 40 with something like
display_nickname : $('#nickname').val() ? $('#nickname').val () : '',
- wrap lines 53-62 of user-profile.dev.js in
if (undefined != value) {}
The 3rd solution seems the most general (and best) to me, since it future-proofs user-profile.js for contexts where any of the fields might not be present. However, I'd really like a 2nd opinion on this before submitting a patch.
Attachments (3)
Change History (12)
#3
@
12 years ago
- Owner set to azaozz
- Resolution set to fixed
- Status changed from new to closed
In [20407]:
#4
follow-up:
↓ 5
@
12 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
We should probably avoid this to begin with: $('#first_name, #last_name, #nickname').blur(
if we're not on the page for it. How much in user-profile.js is the same?
#5
in reply to:
↑ 4
@
12 years ago
Replying to nacin:
Yes, can check if that <select> exists first. The pass strength JS is in the same file and is used on the Add New User screen.
#6
follow-up:
↓ 7
@
12 years ago
return
seems a bit more readable than a long if
block.
20392.2.patch also includes some whitespace fixes as per the coding standards.
#7
in reply to:
↑ 6
;
follow-up:
↓ 8
@
12 years ago
Replying to SergeyBiryukov:
return
seems a bit more readable than a longif
block.
Yes but this is in an anonymous wrapper function that does several things. If it's ever extended to include another jQuery chain, we will have to be careful to add it above or below that return depending where it should run. That seems clearer with an if()
block imho.
#8
in reply to:
↑ 7
@
12 years ago
Replying to azaozz:
If it's ever extended to include another jQuery chain, we will have to be careful to add it above or below that return depending where it should run.
I see, thanks for the explanation. 20392.3.patch builds on 20392.patch with just some minor whitespace fixes, while we're at it.
I guess I would add
before line 53 (similar to point 3).