Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support letters other than A-Z in identifiers in SpEL expressions #30580

Closed
changyoutianxia opened this issue Jun 2, 2023 · 4 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@changyoutianxia
Copy link

changyoutianxia commented Jun 2, 2023

Affects: Spring Framework 5.3.13


SpEL does not support Chinese.

Example:

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    static class Simple {
        private String 张三;
    }

    @Test
    void testSpel() {
        ExpressionParser parser = new SpelExpressionParser();
        Expression exp = parser.parseExpression("张三 == null ? 'World' : 张三");
        Simple rootObject = new Simple("test");

        Object value = exp.getValue(rootObject);
        System.out.println(value);

    }
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 2, 2023
@k143408
Copy link

k143408 commented Jun 2, 2023

Try

ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("'你好,世界!'");
        
String message = (String) expression.getValue();
System.out.println(message); // Prints "你好,世界!"

@sbrannen sbrannen changed the title SpringEl expressions do not support Chinese SpEL does not support properties with Chinese characters Jun 4, 2023
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Jun 4, 2023
@sbrannen sbrannen changed the title SpEL does not support properties with Chinese characters SpEL does not support Chinese characters in property names Jun 4, 2023
@sbrannen sbrannen self-assigned this Jun 4, 2023
@sbrannen
Copy link
Member

sbrannen commented Jun 4, 2023

Try

ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("'你好,世界!'");
        
String message = (String) expression.getValue();
System.out.println(message); // Prints "你好,世界!"

@k143408, your example demonstrates SpEL's support for Chinese characters within a String literal.

Whereas, @changyoutianxia's example uses Chinese characters in a property name (i.e., a getter method in the root context object).

@sbrannen sbrannen changed the title SpEL does not support Chinese characters in property names Support characters other than A-Z in identifiers in SpEL Jun 6, 2023
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 6, 2023
@sbrannen sbrannen added this to the 6.1.x milestone Jun 6, 2023
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Jun 6, 2023
Prior to this commit, when an unsupported character such as "ü" was
encountered in a SpEL expression, the error message was:

Cannot handle (252) 'ü'

With this commit, the error message is now similar to:

Unsupported character 'ü' (252) encountered at position 5 in expression.

See spring-projectsgh-30580
Closes spring-projectsgh-30602
@sbrannen
Copy link
Member

sbrannen commented Jun 6, 2023

@sbrannen sbrannen modified the milestones: 6.1.x, 6.1.0-M1 Jun 6, 2023
@sbrannen
Copy link
Member

sbrannen commented Jun 6, 2023

SpEL does not support Chinese.

This is a known (although undocumented) limitation of SpEL.

Specifically, the SpEL parser imposes the following restrictions on identifiers (property names, field names, and variable names).

('a'..'z'|'A'..'Z'|'_'|'$') ('a'..'z'|'A'..'Z'|'_'|'$'|'0'..'9'|DOT_ESCAPED)*

With regard to letters, only the letters A through Z (ignoring case) are supported in identifiers.

Since this limitation has been in place since SpEL was introduced, we do not plan to modify the current behavior for Spring Framework 6.0.x or previous versions of the framework.

However, we will modify the SpEL Tokenizer to support additional character sets for Spring Framework 6.1.

@sbrannen sbrannen changed the title Support characters other than A-Z in identifiers in SpEL Support letters other than A-Z in identifiers in SpEL Jun 6, 2023
@sbrannen sbrannen changed the title Support letters other than A-Z in identifiers in SpEL Support letters other than A-Z in identifiers in SpEL expressions Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants