Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

String `%` operand raises a coercion error instead of printf-style formatting

Đang mở
#1,340 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

Start with the % handling in src/main/java/com/hubspot/jinjava/el/ext/ExtendedParser.java:421-424 and run the supplied {{ 'number'%r }} reproduction. Trace how AstBinary.MOD processes the operands, then verify that the string-left-operand case renders as Jinja2 does without the reported coercion error.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Jinja2 applies printf-style formatting to 'text' % operand. Jinjava parses % as the JUEL modulo operator and coerces the left operand to a number, so a string left operand fails to render.

Affected: master df50b0d7. Releases 2.7.6, 2.8.3 and 2.8.4 behave the same.

Reproduction

{{ 'number'%r }}

Jinja2 renders number. Jinjava raises:

com.hubspot.jinjava.interpret.FatalTemplateErrorsException: Cannot coerce 'number' of class java.lang.String to class java.lang.Double (incompatible value)

Root cause

ExtendedParser maps the % token to AstBinary.MOD (src/main/java/com/hubspot/jinjava/el/ext/ExtendedParser.java:421-424). The JUEL implementation of MOD converts both operands to numbers, and there is no string formatting path for a string left operand.

Ngôn ngữ chính
Java
Star
785
Fork
184
Merge trung bình
6 ngày 22 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của HubSpot/jinjava

Tất cả issue của HubSpot/jinjava

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.