Skip to content

Commit c001a62

Browse files
avm2: Return correct error for unclosed tags
The problem is that quick-xml returns the same error (UnclosedTag) in 2 distinct cases: 1. Unterminated attribute (Error 1095): <a b='/> 2. Malformed element (Error 1090): <a/><b></b This commit adds logic to differentiate between these cases by: - Checking if any XML events were successfully parsed before the error - If no events were parsed, examining the XML content for attribute patterns - If the content contains '=' and a quote character, it's Error 1095 - Otherwise, it's Error 1090
1 parent 102b5e7 commit c001a62

File tree

2 files changed

+38
-2
lines changed
  • core/src/avm2
  • tests/tests/swfs/from_avmplus/as3/RuntimeErrors/Error1095XmlUnterminatedAttr

2 files changed

+38
-2
lines changed

core/src/avm2/e4x.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,19 @@ fn make_xml_error<'gc>(activation: &mut Activation<'_, 'gc>, err: XmlError) -> E
7777
"Error #1094: XML parser failure: Unterminated comment.",
7878
1094,
7979
),
80+
// FIXME: Based on circumstance, this branch should produce Error #1092 or Error #1097.
81+
// Doing so should fix the from_avmplus/as3/RuntimeErrors/Error1092XmlUnterminatedXmlDecl test.
8082
XmlSyntaxError::UnclosedPIOrXmlDecl => type_error(
8183
activation,
8284
"Error #1097: XML parser failure: Unterminated processing instruction.",
8385
1097,
8486
),
85-
_ => type_error(
87+
XmlSyntaxError::UnclosedTag => type_error(
88+
activation,
89+
"Error #1090: XML parser failure: element is malformed.",
90+
1090,
91+
),
92+
XmlSyntaxError::InvalidBangMarkup => type_error(
8693
activation,
8794
"Error #1090: XML parser failure: element is malformed.",
8895
1090,
@@ -851,6 +858,36 @@ impl<'gc> E4XNode<'gc> {
851858
1088,
852859
)?));
853860
}
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('=')
874+
&& (tag_content.contains('\'') || tag_content.contains('"'))
875+
{
876+
return Err(Error::avm_error(type_error(
877+
activation,
878+
"Error #1095: XML parser failure: Unterminated attribute.",
879+
1095,
880+
)?));
881+
}
882+
}
883+
}
884+
// Otherwise, it's a malformed element
885+
return Err(Error::avm_error(type_error(
886+
activation,
887+
"Error #1090: XML parser failure: element is malformed.",
888+
1090,
889+
)?));
890+
}
854891
Err(err) => return Err(make_xml_error(activation, err)),
855892
};
856893

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
num_ticks = 1
2-
known_failure = true

0 commit comments

Comments
 (0)