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
Fix to_param when attribute has multibyte character #13386
Conversation
This seems good to me. @javan what do you think? Will this break any behavior we are relying? |
Typically |
👍 on the change. I'm not crazy about building on the nest of |
When I wrote the Unicorn mode ON: It would be nice, I think, to allow an option to not delete UTF-8 characters, so that you could generate a parameterized string like Unicorn mode OFF. |
@norman I agree with you but even if we generate parameterized string with UTF-8 characters our router is not prepared to handle it very well (I was bite for a lot of bugs related with this in the last month). So I think we should stay with this version here and when we change the router to handle UTF-8 characters we can change |
Yep, fine for 4.1 and then look at it again when we support IRIs |
"#{default}-#{result.squish.truncate(20, separator: /\s/, omission: nil).parameterize}" | ||
if (default = super()) && (result = send(method_name).to_s).present? && | ||
(param = result.squish.truncate(20, separator: /\s/, omission: nil).parameterize).present? | ||
"#{default}-#{param}" | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javan Thank you for your feedback. I will fix like below and then rebase, fine?
result = send(method_name).to_s
param = result.squish.truncate(20, separator: /\s/, omission: nil).parameterize
if (default = super()) && param.present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the short-circuiting nature of the current structure makes the most sense. We don't need result
unless there's a default
and don't need param
unless there's a result
. I guess leave it as-is or fix up the formatting a little. I'm not sure what the preferred style in Rails is, perhaps:
define_method :to_param do
if (default = super()) &&
(result = send(method_name).to_s).present? &&
(param = result.squish.truncate(20, separator: /\s/, omission: nil).parameterize).present?
"#{default}-#{param}"
else
default
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the one @javan used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelfranca Thank you! I will fix it and force push.
@javan @rafaelfranca Thank you for your advice. I updated the style. |
Fix to_param when attribute has multibyte character
Thank you so much for trying the beta and fixing this bug. |
@rafaelfranca So, does Rails support |
@kuldeepaggarwal RFC 3986 requires path chars other than alphanumerics to be %-encoded. HTML5 includes partial support for IRIs and it's something we'll be investigating for a future version of Rails. |
Please Do Investigate support for routing IRIs in Journey! Major performance win if we can avoid transliteration when we to_param to generate slugs. |
When attribute has only multibyte character, to_param returns id + "-". I think it is not pretty.