Closed Bug 679671 Opened 15 years ago Closed 15 years ago

element.setAttribute trim leading and trailing whitespaces when the attribute is of type long or unsigned long and the value an valid integer

Categories

(Core :: DOM: Core & HTML, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla9

People

(Reporter: mounir, Assigned: bzbarsky)

References

Details

Attachments

(1 file)

Testcase: data:text/html,<script>var i = document.createElement("input"); i.setAttribute("maxlength", " 22 "); alert("attr: '" + i.getAttribute("maxlength") + "'");</script> Should show ' 22 ' but shows '22'. Webkit and Presto correctly show ' 22 '. Also, this is working as expected if the attribute isn't of type long (like 'type') or if the value isn't a valid integer (like ' foo '). Note that it doesn't work for unsigned long and long attributes (can be checked with 'size'). This bug has been found during the work for a int attribute reflection test suite (bug 669578). So we do not need to write tests for this bug specifically. The code concerned by this bug is likely here: content/base/src/nsAttrValue.{h,cpp} The code in nsAttrValue is called by some code here: content/html/content/src/nsGenericHTMLElement.{h,cpp} Actually, the macros in the header are used by HTML elements like: content/html/content/src/nsHTMLInputElement.cpp What is likely to happen is that the code parse the value looking for a number, found it but saves the string representation being the actual number instead of the number with the leading and trailing whitespaces.
This is just a silly bug in nsAttrValue::ParseNonNegativeIntValue. It does this: SetIntValueAndType(originalVal, eInteger, nsnull); whereas it should do this: SetIntValueAndType(originalVal, eInteger, strict ? nsnull : &aString); ParsePositiveIntValue has the same issue. Mounir, do you already have tests for this that you want to attach here?
Assignee: nobody → bzbarsky
Priority: -- → P2
Whiteboard: [mentor=volkmar] → [need review]
Comment on attachment 555930 [details] [diff] [review] Save the original string when parsing nonnegative or positive integer values shows them as non-strict. Review of attachment 555930 [details] [diff] [review]: ----------------------------------------------------------------- Oups, that was my fault... Thank you for fixing that :) r=mounir
Attachment #555930 - Flags: review?(mounir) → review+
(In reply to Boris Zbarsky (:bz) from comment #1) > Mounir, do you already have tests for this that you want to attach here? Bug 669578 has tests for that.
Whiteboard: [need review] → [need landing]
Flags: in-testsuite?
Target Milestone: --- → mozilla9
Status: NEW → RESOLVED
Closed: 15 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: