Skip to content

Commit 16972f5

Browse files
avm2: Adjust error handling logic so that tests pass
1 parent f01c77e commit 16972f5

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

core/src/avm2/e4x.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ fn make_xml_error<'gc>(activation: &mut Activation<'_, 'gc>, err: XmlError) -> E
8686
),
8787
XmlSyntaxError::UnclosedTag => type_error(
8888
activation,
89-
"Error #1095: XML parser failure: Unterminated attribute.",
90-
1095,
89+
"Error #1090: XML parser failure: element is malformed.",
90+
1090,
9191
),
9292
XmlSyntaxError::InvalidBangMarkup => type_error(
9393
activation,
@@ -858,6 +858,34 @@ impl<'gc> E4XNode<'gc> {
858858
1088,
859859
)?));
860860
}
861+
Err(XmlError::Syntax(XmlSyntaxError::UnclosedTag))
862+
if top_level.is_empty() && open_tags.is_empty() =>
863+
{
864+
// Check if this looks like an unterminated attribute by examining the XML content
865+
// Look for pattern: < followed by tag name, then space and attribute with = and quote
866+
let error_pos = parser.error_position() as usize;
867+
868+
if error_pos < data_utf8.len() {
869+
let rest = &data_utf8[error_pos..];
870+
// Check if we have an attribute pattern (contains '=' and a quote)
871+
if let Some(tag_end_idx) = rest.find('>') {
872+
let tag_content = &rest[..tag_end_idx];
873+
if tag_content.contains('=') && (tag_content.contains('\'') || tag_content.contains('"')) {
874+
return Err(Error::avm_error(type_error(
875+
activation,
876+
"Error #1095: XML parser failure: Unterminated attribute.",
877+
1095,
878+
)?));
879+
}
880+
}
881+
}
882+
// Otherwise, it's a malformed element
883+
return Err(Error::avm_error(type_error(
884+
activation,
885+
"Error #1090: XML parser failure: element is malformed.",
886+
1090,
887+
)?));
888+
}
861889
Err(err) => return Err(make_xml_error(activation, err)),
862890
};
863891

0 commit comments

Comments
 (0)