Closed Bug 244632 Opened 22 years ago Closed 22 years ago

Lead in space characters in new Option(" ",.....)

Categories

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

x86
Windows XP
defect
Not set
minor

Tracking

()

RESOLVED DUPLICATE of bug 59248

People

(Reporter: ChrisRath, Unassigned)

References

()

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040206 Firefox/0.8 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040206 Firefox/0.8 Got some software that adds new Options() to select dropdown boxes on the fly via JavaScript. I'm using spaces for indentation to indicate levels. Mozilla renders escaped space characters ok in html but seems to have problems with adding new options that have lead-in spaces (they always appear to be trimmed). Test script demonstrating the problem can found on my webpage at select-option.html. The line with "Test A" is an initial option via normal html. The line with "Test B" is an added option that is supposed to have 6 blank characters in front - it's the one that is the problem. The line with "Test C" uses String.fromCharCode(0xA0) instead of blanks to show what kind of indentation desired. The line with "Test D" is an experiment to show that html type escaping doesn't solve the problem. Script source follows: <html> <head><title>Test</title></head> <body> <form id='MyForm' action='test.html' method='POST'> <select name='DropDown' id='idDropDown'> <option value='A'>&nbsp; &nbsp; &nbsp; TestA</option> </select> </form> <script language='JavaScript' type='text/javascript'> document.getElementById("idDropDown").options[1] = new Option(" TestB", "B", false, false); document.getElementById("idDropDown").options[2] = new Option(String.fromCharCode(0xA0, 0x20, 0xA0, 0x20, 0xA0, 0x20) + "TestC", "C", false, false); document.getElementById("idDropDown").options[3] = new Option("&nbsp; &nbsp; &nbsp; TestD", "D", false, false); </script> </body> </html> </html> Reproducible: Always Steps to Reproduce: 1. new Option(" any string with leading spaces",....) 2. 3. Actual Results: The text for the option always gets right-trimmed Expected Results: Since the html escaping doesn't apply within JavaScript, the blank spaces probably need to be retained. The workaround is fairly easy: use String.fromCharCode(0x0A) function to replace the lead in spaces.
Two bugs in my bug report: Make that Left-Trimmed (not right trimmed) and Make that String.fromCharCode(0xA0) (not String.fromCharCode(0x0A))
The spaces _are_ retained in the DOM. They're stripped at display time. In IE, the spaces are retained in the DOM, when doing new Option() but stripped out when parsing an <option> in HTML, which is totally bogus. *** This bug has been marked as a duplicate of 59248 ***
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago
Resolution: --- → DUPLICATE
Still trying to figure out the best way to search around here. Definitely a dup of the problem. Thanks. As for ie's behavior, I can't say which behavior is correct - as it's probably not part of any specification. Hesitated in posting this as a bug, as I thought it quite possible it was a conscious design decision. It's definitely a minor issue in my books. Be that as it may, my opinion is that neither behavior (mozilla or ie) is correct. The correct behavior seems to me to make the string be an html form of the string, such that i can embed spaces with the &nbsp; similar to the embedded options. The use of 0xA0 as the character achieves this as a workaround. Which is mostly why I posted the thing was to show the workaround of embedding that character in lieu of the space characters. Anyhow, it's a resolved issue for my app. Thanks.
You need to log in before you can comment on or make changes to this bug.