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 6c4ae81499e9c19af5c77f91bdc73dcc2c70c71c
Author: Josh Tynjala <[email protected]>
AuthorDate: Wed Nov 6 09:12:11 2024 -0800

    CSSFontFace: fix exception when src attribute value is unexpected type
---
 .../royale/compiler/internal/css/CSSFontFace.java  | 12 +++++-
 .../problems/CSSInvalidDescriptorValueProblem.java | 45 ++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSFontFace.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSFontFace.java
index bb45dc954..7d8fcab89 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSFontFace.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSFontFace.java
@@ -30,6 +30,7 @@ import org.apache.royale.compiler.css.FontFaceSourceType;
 import org.apache.royale.compiler.css.ICSSFontFace;
 import org.apache.royale.compiler.css.ICSSProperty;
 import org.apache.royale.compiler.css.ICSSPropertyValue;
+import org.apache.royale.compiler.problems.CSSInvalidDescriptorValueProblem;
 import org.apache.royale.compiler.problems.CSSRequiredDescriptorProblem;
 import org.apache.royale.compiler.problems.ICompilerProblem;
 
@@ -123,9 +124,18 @@ public class CSSFontFace extends CSSNodeBase implements 
ICSSFontFace
         else
         {
             if (srcValue instanceof CSSArrayPropertyValue)
+            {
                 source = 
(CSSFunctionCallPropertyValue)(srcValue).getNthChild(0);
-            else
+            }
+            else if (srcValue instanceof CSSFunctionCallPropertyValue)
+            {
                 source = (CSSFunctionCallPropertyValue)srcValue;
+            }
+            else
+            {
+                source = null;
+                problems.add(new CSSInvalidDescriptorValueProblem(srcValue, 
"@font-face", "src", srcValue));
+            }
         }
 
         if (fontFamilyValue == null)
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/problems/CSSInvalidDescriptorValueProblem.java
 
b/compiler/src/main/java/org/apache/royale/compiler/problems/CSSInvalidDescriptorValueProblem.java
new file mode 100644
index 000000000..5ef6b05de
--- /dev/null
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/problems/CSSInvalidDescriptorValueProblem.java
@@ -0,0 +1,45 @@
+/*
+ *
+ *  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.common.ISourceLocation;
+import org.apache.royale.compiler.css.ICSSPropertyValue;
+
+/**
+ * Problem generated when a CSS @font-face at-rule has an invalid src 
attribute.
+ */
+public final class CSSInvalidDescriptorValueProblem extends CSSProblem
+{
+       public static final String DESCRIPTION =
+               "The '${atRule}' rule requires a valid '${descriptorName}' 
descriptor value. Unexpected '${descriptorValue}'";
+       
+       public CSSInvalidDescriptorValueProblem(ISourceLocation location, 
String atRule, String descriptorName, ICSSPropertyValue descriptorValue)
+       {
+               super(location);
+               this.atRule = atRule;
+               this.descriptorName = descriptorName;
+               this.descriptorValue = descriptorValue != null ? 
descriptorValue.toString() : "null";
+       }
+       
+       public final String atRule;
+       public final String descriptorName;
+       public final String descriptorValue;
+}
+ 
\ No newline at end of file

Reply via email to