Skip to content

Commit 352c15b

Browse files
committed
chore: APIs backward compatibility
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
1 parent f0fb3d2 commit 352c15b

File tree

2 files changed

+127
-3
lines changed

2 files changed

+127
-3
lines changed

src/main/java/com/googlecode/aviator/parser/ExpressionParser.java

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,118 @@ public void parseFactor() {
724724
}
725725
}
726726

727+
/**
728+
* @deprecated Use {@link #parseTernary()} instead.
729+
*/
730+
@Deprecated
731+
public boolean ternary() {
732+
return parseTernary();
733+
}
734+
735+
/**
736+
* @deprecated Use {@link #parseLogicalOr()} instead.
737+
*/
738+
@Deprecated
739+
public void join() {
740+
parseLogicalOr();
741+
}
742+
743+
/**
744+
* @deprecated Use {@link #parseBitOr()} instead.
745+
*/
746+
@Deprecated
747+
public void bitOr() {
748+
parseBitOr();
749+
}
750+
751+
/**
752+
* @deprecated Use {@link #parseBitXor()} instead.
753+
*/
754+
@Deprecated
755+
public void xor() {
756+
parseBitXor();
757+
}
758+
759+
/**
760+
* @deprecated Use {@link #parseBitAnd()} instead.
761+
*/
762+
@Deprecated
763+
public void bitAnd() {
764+
parseBitAnd();
765+
}
766+
767+
/**
768+
* @deprecated Use {@link #parseLogicalAnd()} instead.
769+
*/
770+
@Deprecated
771+
public void and() {
772+
parseLogicalAnd();
773+
}
774+
775+
/**
776+
* @deprecated Use {@link #parseEquality()} instead.
777+
*/
778+
@Deprecated
779+
public void equality() {
780+
parseEquality();
781+
}
782+
783+
/**
784+
* @deprecated Use {@link #parseRelational()} instead.
785+
*/
786+
@Deprecated
787+
public void rel() {
788+
parseRelational();
789+
}
790+
791+
/**
792+
* @deprecated Use {@link #parseShift()} instead.
793+
*/
794+
@Deprecated
795+
public void shift() {
796+
parseShift();
797+
}
798+
799+
/**
800+
* @deprecated Use {@link #parseAdditive()} instead.
801+
*/
802+
@Deprecated
803+
public void expr() {
804+
parseAdditive();
805+
}
806+
807+
/**
808+
* @deprecated Use {@link #parseExponent()} instead.
809+
*/
810+
@Deprecated
811+
public void exponent() {
812+
parseExponent();
813+
}
814+
815+
/**
816+
* @deprecated Use {@link #parseMultiplicative()} instead.
817+
*/
818+
@Deprecated
819+
public void term() {
820+
parseMultiplicative();
821+
}
822+
823+
/**
824+
* @deprecated Use {@link #parseUnary()} instead.
825+
*/
826+
@Deprecated
827+
public void unary() {
828+
parseUnary();
829+
}
830+
831+
/**
832+
* @deprecated Use {@link #parseFactor()} instead.
833+
*/
834+
@Deprecated
835+
public void factor() {
836+
parseFactor();
837+
}
838+
727839

728840

729841
private boolean parseFactor0() {
@@ -932,8 +1044,13 @@ private void checkVariableName(final Token<?> token) {
9321044
return;
9331045
}
9341046
if (!((Variable) token).isQuote()) {
935-
String[] names = token.getLexeme().split("\\.");
936-
for (String name : names) {
1047+
String[] names = token.getLexeme().split("\\.", -1);
1048+
for (int i = 0; i < names.length; i++) {
1049+
String name = names[i];
1050+
if (name.isEmpty() && i == names.length - 1) {
1051+
// Keep compatibility with existing trailing-dot syntax, e.g. "use java.util."
1052+
continue;
1053+
}
9371054
if (!isValidPropertySegment(name)) {
9381055
reportSyntaxError("illegal identifier: " + name);
9391056
}
@@ -943,7 +1060,7 @@ private void checkVariableName(final Token<?> token) {
9431060

9441061
private boolean isValidPropertySegment(final String segment) {
9451062
if (segment == null || segment.isEmpty()) {
946-
return true; // For formats like "a.[0].b"
1063+
return false;
9471064
}
9481065

9491066
int bracketIdx = segment.indexOf('[');

src/test/java/com/googlecode/aviator/test/function/QuoteVarTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Map;
66
import org.junit.Test;
77
import com.googlecode.aviator.AviatorEvaluator;
8+
import com.googlecode.aviator.exception.ExpressionSyntaxErrorException;
89
import static com.googlecode.aviator.TestUtils.assertEquals;
910

1011

@@ -142,4 +143,10 @@ public void testPropertyChainWhenNoFullKey() {
142143
// When "a.b.c" key doesn't exist, should traverse property chain
143144
assertEquals("property-chain-value", AviatorEvaluator.execute("a.b.c", env));
144145
}
146+
147+
148+
@Test(expected = ExpressionSyntaxErrorException.class)
149+
public void testInvalidPropertyChainWithEmptySegment() {
150+
AviatorEvaluator.execute("a..b");
151+
}
145152
}

0 commit comments

Comments
 (0)