Opened 14 months ago
Closed 13 months ago
#20392 closed defect (bug) (fixed)
user-profile.js causing Javascript error in user-new.php
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.4 |
| Component: | Users | Version: | 3.3.1 |
| Severity: | normal | Keywords: | 2nd-opinion |
| Cc: | pbiron |
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)
comment:1
SergeyBiryukov — 14 months ago
- Milestone changed from Awaiting Review to 3.4
- Owner set to azaozz
- Resolution set to fixed
- Status changed from new to closed
In [20407]:
- 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?
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.
SergeyBiryukov — 13 months ago
comment:6
follow-up:
↓ 7
SergeyBiryukov — 13 months 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.
Replying to SergeyBiryukov:
return seems a bit more readable than a long if 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.
SergeyBiryukov — 13 months ago
comment:8
in reply to:
↑ 7
SergeyBiryukov — 13 months 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).