Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avm2: Fix E4X [[Replace]] implementation bug #13783

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/src/avm2/e4x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,11 @@ impl<'gc> E4XNode<'gc> {
}

// 5. If Type(V) is XML and V.[[Class]] ∈ {"element", "comment", "processing-instruction", "text"}
if let Some(xml) = value.as_object().and_then(|x| x.as_xml_object()) {
if matches!(*xml.node().kind(), E4XNodeKind::Attribute(_)) {
return Ok(());
}

if let Some(xml) = value
.as_object()
.and_then(|x| x.as_xml_object())
.filter(|x| !matches!(*x.node().kind(), E4XNodeKind::Attribute(_)))
{
// 5.a. If V.[[Class]] is “element” and (V is x or an ancestor of x) throw an Error exception
if matches!(*xml.node().kind(), E4XNodeKind::Element { .. })
&& self.ancestors().any(|x| E4XNode::ptr_eq(x, *xml.node()))
Expand Down
18 changes: 18 additions & 0 deletions tests/tests/swfs/avm2/issue_13780/Test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package {
import flash.display.Sprite;

public class Test extends Sprite {}
}

// Issue 13780: Replace does not work with attribute nodes.

var xml = new XML('<val attr="val"/>');
var attr = xml.@attr[0]; // Fooled by XMLList again...
trace(attr);
trace(attr.nodeKind());

var target = new XML('<root><child1/><child2/><child3/></root>');

trace(target);
target.replace(1, attr);
trace(target);
12 changes: 12 additions & 0 deletions tests/tests/swfs/avm2/issue_13780/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
val
attribute
<root>
<child1/>
<child2/>
<child3/>
</root>
<root>
<child1/>
val
<child3/>
</root>
Binary file added tests/tests/swfs/avm2/issue_13780/test.swf
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm2/issue_13780/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_ticks = 1