wimdeblauwe / htmx-spring-boot

Spring Boot and Thymeleaf helpers for working with htmx
Apache License 2.0
423 stars 41 forks source link

spring boot 3.2.3: umlaut encoding issue? #99

Closed resmo closed 4 months ago

resmo commented 4 months ago

Summary

I am experiencing an issue I only see with htmx responses that is why I open the issue here, but it might be a spring boot 3.2.3 issue.

After switching form spring boot 3.2.2 to 3.2.3 I see broken "umlauts".

Screenshot from 2024-02-23 17-49-30

Response header looks fine, content "looks" identical but the weird thing is that the content length is different, off by 1 B (3.2.3 has -1 B). Unsure if this is the issue.

Spring Boot

3.2.3

Details

3.2.3

HTTP/1.1 200 
Content-Type: text/html;charset=UTF-8
Content-Language: de
Content-Length: 214
Date: Fri, 23 Feb 2024 16:08:47 GMT
Keep-Alive: timeout=60
Connection: keep-alive

3.2.2

HTTP/1.1 200 
Content-Type: text/html;charset=UTF-8
Content-Language: de
Content-Length: 215
Date: Fri, 23 Feb 2024 16:14:01 GMT
Keep-Alive: timeout=60
Connection: keep-alive
resmo commented 4 months ago

reproducer https://github.com/resmo/spring-boot-3.2.3-demo-htmx-umlauts

The issue only shows up in 3.2.3 with this htmx-spring-boot.

resmo commented 4 months ago

seems the issue does no show if the browser content language is set to "english". I tested with german or german (switzerland)

resmo commented 4 months ago

it seems related to spring framework 6.1.4 (not spring boot). But the thing is, I only see it using htmx-spring-boot, not "normal" thymeleaf responses and mentioned before, if accept language header is de (!= en).

Do you have a clue?

xhaggi commented 4 months ago

Could you please provide the request and response headers for both the direct request and the htmx request!

resmo commented 4 months ago

Could you please provide the request and response headers for both the direct request and the htmx request!

HTMX

spring framework 6.1.3 (works as expected)

request

GET /umlauts2 HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0
Accept: */*
Accept-Language: de-CH,de;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
HX-Request: true
HX-Current-URL: http://localhost:8080/
DNT: 1
Connection: keep-alive
Referer: http://localhost:8080/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
Pragma: no-cache
Cache-Control: no-cache

response

HTTP/1.1 200 
Content-Type: text/html;charset=UTF-8
Content-Language: de-CH
Content-Length: 51
Date: Mon, 26 Feb 2024 16:31:44 GMT
Keep-Alive: timeout=60
Connection: keep-alive

spring framework 6.1.4 (broken)

GET /umlauts2 HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0
Accept: */*
Accept-Language: de-CH,de;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
HX-Request: true
HX-Current-URL: http://localhost:8080/
DNT: 1
Connection: keep-alive
Referer: http://localhost:8080/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
Pragma: no-cache
Cache-Control: no-cache

response

HTTP/1.1 200 
Content-Type: text/html;charset=UTF-8
Content-Language: de-CH
Content-Length: 48
Date: Mon, 26 Feb 2024 16:34:06 GMT
Keep-Alive: timeout=60
Connection: keep-alive

Not-HTMX

spring framewor 6.1.3 (works)

request

GET / HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: de-CH,de;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
DNT: 1
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: cross-site
Pragma: no-cache
Cache-Control: no-cache

response

HTTP/1.1 200 
Content-Type: text/html;charset=UTF-8
Content-Language: de-CH
Transfer-Encoding: chunked
Date: Mon, 26 Feb 2024 16:41:43 GMT
Keep-Alive: timeout=60
Connection: keep-alive

spring framewor 6.1.4 (broken)

request

GET / HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: de-CH,de;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: cross-site
Pragma: no-cache
Cache-Control: no-cache

response

HTTP/1.1 200 
Content-Type: text/html;charset=UTF-8
Content-Language: de-CH
Transfer-Encoding: chunked
Date: Mon, 26 Feb 2024 16:34:06 GMT
Keep-Alive: timeout=60
Connection: keep-alive
resmo commented 4 months ago

there is currently a analysis of a regression going on in https://github.com/spring-projects/spring-framework/issues/32317 which might be related

sbrannen commented 4 months ago

We've pushed a fix for Spring Framework 6.1.x.

See https://github.com/spring-projects/spring-framework/issues/32317#issuecomment-1964819639 for details.

resmo commented 4 months ago

closing, the fix pushed Spring Framework 6.1.x. worked for me!