phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
5.99k stars 902 forks source link

Consider more possible characters when prefixing unused form data key #3288

Closed c4710n closed 3 weeks ago

c4710n commented 1 month ago

Even though - is rarely used as key in Elixir, there are instances when it is used, so it's better to consider it.

Current implementation of prependFormDataKey fails to handle the key containing -:

prependFormDataKey('en', '_unused_')    // '_unused_en'    - good
prependFormDataKey('en-US', '_unused_') // 'en-_unused_US' - bad

This PR aims to fix above issue by considering more possible characters. The result:

prependFormDataKey('en', '_unused_')    // '_unused_en'    - good
prependFormDataKey('en-US', '_unused_') // '_unused_en-US' - good
SteffenDE commented 1 month ago

Instead of special casing -, would it make sense to just match everything in the last []?

Something like ([^\[\]]+)(\]?$)

c4710n commented 1 month ago

@SteffenDE Indeed, the RE provided by you is much better. I have updated this PR.

josevalim commented 3 weeks ago

:green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart: