Closed Bug 280939 Opened 20 years ago Closed 20 years ago

cloneNode does not do deep copy properly

Categories

(SeaMonkey :: General, defect)

x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: simonf, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020

If you go to the specified URL and click the button several times,
cloneNode(true) will be called on an input field. Each time a copy is created,
it's assigned a new name by appending the value of 'count', which is then
incremented. However, the original's name should not be affected. If you run
this in IE 6, you will see that the original's name is always the same. However,
in Mozilla and Firefox, when I change the name of the copy, the name of the
original also gets changed. This tells me that deepCopy is not copying the name,
but retains the reference to it. If I change deepCopy(true) to deepCopy(false),
both IE and Mozilla change the name of the original, so most probably the input
argument to deepCopy is not processed correctly.

This also happens in Firefox 1.0 and Mozilla 1.7.5 on Windows.

Reproducible: Always

Steps to Reproduce:
1. Open the specified file.
2. Click the button several times.
3. Observe javascript popups with incorrect names.

Actual Results:  
The name of the original "golden" input changes from 'input' to 'input1' to
'input12' to 'input123' etc.

Expected Results:  
The name of the original input box should always be 'input', and the cloned
boxes should be called 'input1', 'input2', 'input3'.
Your script doesn't assign unique ID attribute value to cloned object.
This causes multiple objects with ID='aaa'.
According to your description(and actual result with Mozilla), Mozilla seems to
return last object of ID='aaa', but IE seems to return first object of ID='aaa'.
This is the reason why funny result of your script.

I don't know which object should be returned to document.getElementById('aaa')
when multiple objects of ID='aaa' are defined.
(I guess "not defined by W3C", though.)
I think that expecting "first occurence is returned any time/in any environment"
is wrong.
You are totally right. This fixes the problem. Thanks!

(In reply to comment #1)
> Your script doesn't assign unique ID attribute value to cloned object.
> This causes multiple objects with ID='aaa'.
> According to your description(and actual result with Mozilla), Mozilla seems to
> return last object of ID='aaa', but IE seems to return first object of ID='aaa'.
> This is the reason why funny result of your script.
> 
> I don't know which object should be returned to document.getElementById('aaa')
> when multiple objects of ID='aaa' are defined.
> (I guess "not defined by W3C", though.)
> I think that expecting "first occurence is returned any time/in any environment"
> is wrong.
> 

Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Simon Ilyushchenko, if here is bugzilla for your script development,
FIXED is absolutely valid close code.
But here is bugzilla for Mozilla development.
Reopening to close as INALID.
Status: RESOLVED → UNCONFIRMED
Resolution: FIXED → ---
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago20 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.