You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2025/11/10 16:00:12 UTC

(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing xalan-j xpath 3.1 parse error handling improvements to 'if' expression

This is an automated email from the ASF dual-hosted git repository.

mukulg pushed a commit to branch xalan-j_xslt3.0_mvn
in repository https://gitbox.apache.org/repos/asf/xalan-java.git


The following commit(s) were added to refs/heads/xalan-j_xslt3.0_mvn by this push:
     new 6b9f2bf7c committing xalan-j xpath 3.1 parse error handling improvements to 'if' expression
6b9f2bf7c is described below

commit 6b9f2bf7ca581e52721503d503690318b54e7bf4
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Mon Nov 10 21:29:42 2025 +0530

    committing xalan-j xpath 3.1 parse error handling improvements to 'if' expression
---
 .../java/org/apache/xpath/compiler/XPathParser.java  | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/xpath/compiler/XPathParser.java b/src/main/java/org/apache/xpath/compiler/XPathParser.java
index aad8f41ea..6be9f2796 100644
--- a/src/main/java/org/apache/xpath/compiler/XPathParser.java
+++ b/src/main/java/org/apache/xpath/compiler/XPathParser.java
@@ -2857,8 +2857,8 @@ public class XPathParser
       String[] strArr = strValue.split(",if");
       if (strArr.length > 1) {
     	 // There are sequence of, at-least two XPath 'if' expressions
-    	 for (int i = 1; i < strArr.length; i++) {
-    		strArr[i] = "if" + strArr[i]; 
+    	 for (int idx = 1; idx < strArr.length; idx++) {
+    		strArr[idx] = "if" + strArr[idx]; 
     	 }
     	 
     	 List<String> strList = Arrays.asList(strArr);
@@ -2883,17 +2883,22 @@ public class XPathParser
       
       int tokenQueueSize = (m_ops.m_tokenQueue).size();
       
-      int thenTokenEffectiveComputedIdx = 0;
+      int thenTokenEffectiveComputedIdx = -1;
       
       for (int idx = 0; idx < tokenQueueSize; idx++) {
     	  Object tokenObj = (m_ops.m_tokenQueue).elementAt(idx);
     	  String tokenStrValue = tokenObj.toString();
     	  if ("then".equals(tokenStrValue)) {
-    		 thenTokenEffectiveComputedIdx = idx;
+    		 thenTokenEffectiveComputedIdx = idx;    		 
     		 break;
     	  }
       }
       
+      if (thenTokenEffectiveComputedIdx == -1) {
+    	 throw new javax.xml.transform.TransformerException("XPST0003 : An XPath 'if' expression doesn't contain "
+    	 		                                                                                     + "expected token 'then'.", m_sourceLocator); 
+      }
+      
       StringBuffer probableBranchConditionXPathStrBuff = new StringBuffer();
       for (int idx = 1; idx < thenTokenEffectiveComputedIdx; idx++) {
     	  Object tokenObj = (m_ops.m_tokenQueue).elementAt(idx);
@@ -2926,7 +2931,7 @@ public class XPathParser
       thenTokenEffectiveComputedIdx = (thenTokenComputedRevisedIdx != 0) ? 
     		                                                    thenTokenComputedRevisedIdx : thenTokenEffectiveComputedIdx;
       
-      int elseTokenEffectiveComputedIdx = 0;
+      int elseTokenEffectiveComputedIdx = -1;
       
       for (int idx = (tokenQueueSize - 1); idx >= 0; idx--) {
     	  Object tokenObj = (m_ops.m_tokenQueue).elementAt(idx);
@@ -2937,6 +2942,11 @@ public class XPathParser
     	  }
       }
       
+      if (elseTokenEffectiveComputedIdx == -1) {
+    	  throw new javax.xml.transform.TransformerException("XPST0003 : An XPath 'if' expression doesn't contain "
+                                                                                                      + "expected token 'else'.", m_sourceLocator); 
+      }
+      
       StringBuffer probableElseExprStrBuff = new StringBuffer();
       for (int idx = (elseTokenEffectiveComputedIdx + 1); idx < tokenQueueSize; idx++) {
     	  Object tokenObj = (m_ops.m_tokenQueue).elementAt(idx);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org