[SPR-17621] HierarchicalUriComponents.encodeUriComponent() method can not encode Pchar Created: 22/Dec/18  Updated: 15/Jan/19  Resolved: 23/Dec/18

Status: Closed
Project: Spring Framework
Component/s: Web
Affects Version/s: 5.0.6
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: sunbufu Assignee: Brian Clozel
Resolution: Works as Designed Votes: 0
Labels: mvc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: JPEG File 1.jpg     JPEG File 2.jpg     JPEG File 3.jpg    
Reference URL: https://github.com/spring-projects/spring-framework/blob/5.0.x/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java
Days since last comment: 1 year, 1 week, 4 days ago
Last commented by a User: true
Last updater: Spring Issuemaster

 Description   

Hi guy,

I have a question about HierarchicalUriComponents.encodeUriComponent() method. I think it should encode all special char in url query param, Actually, It can not encode many special char. For example + - ! $ ... in url query param. and my email is sunyoubufu@qq.com . 



 Comments   
Comment by Brian Clozel [ 23/Dec/18 ]

Did you take a loot at the RFC that's referenced from the implementation here?

The RFC 3986 states that the following characters are allowed in a query string (see the appendix A in the ABNF):

query         = *( pchar / "/" / "?" )
pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded   = "%" HEXDIG HEXDIG
sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
                 / "*" / "+" / "," / ";" / "="

This means that sub-delimiters are allowed in query strings and do not need to be percent encoded (that includes +, $).

Now I understand that some legal characters might still have a special meaning. We've applied some changes to be more consistent with the encoding of URLs (see SPR-16860), and I think you're ultimately after what was addressed in SPR-17039 (see the dedicated section in the reference documentation).

Thanks!

Comment by sunbufu [ 23/Dec/18 ]

Got it. Thanks very much.

Comment by Spring Issuemaster [ 14/Jan/19 ]

The Spring Framework has migrated to GitHub Issues. This issue corresponds to spring-projects/spring-framework#22153.

Generated at Sat Jan 25 14:27:39 UTC 2020 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.