This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit ba1a1381d2276cf27778b3307c0067f2b1af2d6f Author: Josh Tynjala <[email protected]> AuthorDate: Mon Oct 27 15:13:22 2025 -0700 MXMLScopeBuilder: report a problem if the className value of fx:Component is not a valid AS3 identifier It was allowing . and other invalid characters. This improves compatibility with the Flex SDK compiler. --- .../internal/parsing/mxml/MXMLScopeBuilder.java | 23 ++++++++++++ .../problems/MXMLInvalidClassNameProblem.java | 43 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/mxml/MXMLScopeBuilder.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/mxml/MXMLScopeBuilder.java index e04e258f0..2cb9af6df 100644 --- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/mxml/MXMLScopeBuilder.java +++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/mxml/MXMLScopeBuilder.java @@ -68,6 +68,7 @@ import org.apache.royale.compiler.mxml.IMXMLTextData.TextType; import org.apache.royale.compiler.mxml.IMXMLUnitData; import org.apache.royale.compiler.problems.ICompilerProblem; import org.apache.royale.compiler.problems.MXMLEmptyAttributeProblem; +import org.apache.royale.compiler.problems.MXMLInvalidClassNameProblem; import org.apache.royale.compiler.problems.MXMLLibraryTagNotTheFirstChildProblem; import com.google.common.collect.ImmutableSet; @@ -622,6 +623,10 @@ public class MXMLScopeBuilder className = attr.getRawValue(); nameStart = attr.getValueStart() + 1; nameEnd = attr.getValueEnd() - 1; + if (!isValidClassName(className)) + { + problems.add(new MXMLInvalidClassNameProblem(attr, className)); + } } // TODO create problem if className has already been set. } @@ -667,6 +672,24 @@ public class MXMLScopeBuilder currentClassScope = oldClassScope; } + private boolean isValidClassName(String className) + { + if (className == null || className.length() == 0 || !Character.isJavaIdentifierStart(className.charAt(0))) + { + return false; + } + + for (int i=1; i < className.length(); i++) + { + if (!Character.isJavaIdentifierPart((className.charAt(i)))) + { + return false; + } + } + + return true; + } + private void processState(IMXMLTagData tag, String qname) { if (!MXMLInstanceNode.isStateClass(qname, project) || tag.getMXMLDialect() == MXMLDialect.MXML_2006) diff --git a/compiler/src/main/java/org/apache/royale/compiler/problems/MXMLInvalidClassNameProblem.java b/compiler/src/main/java/org/apache/royale/compiler/problems/MXMLInvalidClassNameProblem.java new file mode 100644 index 000000000..1eb11962e --- /dev/null +++ b/compiler/src/main/java/org/apache/royale/compiler/problems/MXMLInvalidClassNameProblem.java @@ -0,0 +1,43 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.royale.compiler.problems; + +import org.apache.royale.compiler.mxml.IMXMLTagAttributeData; + +/** + * Problem generated when the <code>className</code> attribute of an + * fx:Component tag is an invalid ActionScript identifier. + */ +public final class MXMLInvalidClassNameProblem extends MXMLSemanticProblem +{ + public static final String DESCRIPTION = + "The ${CLASS_NAME} ${className} is not a valid ActionScript identifier."; + + public MXMLInvalidClassNameProblem(IMXMLTagAttributeData site, String className) + { + super(site); + this.className = className; + } + + // Prevent these from being localized. + public final String CLASS_NAME = "className"; + + public final String className; +}
