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: Handle explicitly imported/used namespace for XML lookup #14800

Merged
merged 2 commits into from
Jan 17, 2024
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
12 changes: 12 additions & 0 deletions core/src/avm2/multiname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ pub enum NamespaceSet<'gc> {
}

impl<'gc> NamespaceSet<'gc> {
pub fn new(set: Vec<Namespace<'gc>>, mc: &Mutation<'gc>) -> Self {
if set.len() == 1 {
NamespaceSet::single(set[0])
} else {
NamespaceSet::multiple(set, mc)
}
}

pub fn multiple(set: Vec<Namespace<'gc>>, mc: &Mutation<'gc>) -> Self {
Self::Multiple(Gc::new(mc, set))
}
Expand Down Expand Up @@ -469,6 +477,10 @@ impl<'gc> Multiname<'gc> {
AvmString::new(mc, uri)
}

pub fn set_ns(&mut self, ns: NamespaceSet<'gc>) {
self.ns = ns;
}

pub fn set_single_namespace(&mut self, namespace: Namespace<'gc>) {
self.ns = NamespaceSet::Single(namespace);
}
Expand Down
23 changes: 19 additions & 4 deletions core/src/avm2/object/xml_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::avm2::activation::Activation;
use crate::avm2::api_version::ApiVersion;
use crate::avm2::e4x::{string_to_multiname, E4XNode, E4XNodeKind};
use crate::avm2::error::make_error_1087;
use crate::avm2::multiname::NamespaceSet;
use crate::avm2::object::script_object::ScriptObjectData;
use crate::avm2::object::{ClassObject, Object, ObjectPtr, TObject, XmlListObject};
use crate::avm2::string::AvmString;
Expand Down Expand Up @@ -647,10 +648,24 @@ fn handle_input_multiname<'gc>(
&& !name.is_any_name()
&& !name.is_any_namespace()
{
name.local_name()
if let Some(mut new_name) = name
.local_name()
.map(|name| string_to_multiname(activation, name))
.unwrap_or(name)
} else {
name
{
// Copy the namespaces from the previous name,
// but make sure to definitely include the public namespace.
if !new_name.is_any_namespace() {
let mut ns = Vec::new();
ns.extend(name.namespace_set());
if !name.contains_public_namespace() {
ns.push(activation.avm2().public_namespace_base_version);
}
new_name.set_ns(NamespaceSet::new(ns, activation.gc()));
}

return new_name;
}
}

name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.ruffle.namespaces
{
public namespace example = "http://example.org/";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ruffle.test {
import flash.display.Sprite;

import org.ruffle.namespaces.*;

use namespace example;

public class Test extends Sprite {
public var xml: XML = <root xmlns="http://example.org/"><hello>world</hello></root>

public function Test() {
trace(xml.toXMLString());
trace("xml.hello: " + xml.hello);
trace('xml["hello"]: ' + xml["hello"]);
}
}
}
5 changes: 5 additions & 0 deletions tests/tests/swfs/avm2/xml_explicit_use_namespace/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<root xmlns="http://example.org/">
<hello>world</hello>
</root>
xml.hello: world
xml["hello"]: world
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm2/xml_explicit_use_namespace/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_frames = 1