This project is archived and is in readonly mode.
error_messages_for doesn't html escape it's messages
-
DHH
Why should the message be escaped? Presumably it's a combination of a fixed error message and an attribute. Neither which have user input?
-
Zach Dennis
If the error message contains <, >, &, or any of the other characters that need to be escaped then you're in for a surprise when it does get rendered. It seems like html escaping error messages at model level isn't the right place to do that.
Granted, this problem doesn't come up all that often, given I'm the first reporting it in the past 3 - 4 years. It seems like having this become a non-issue (rather than just a 1% occurrence) by putting the responsibility of html escaping in error_messages_for is a good thing to do.
If it doesn't make it in there, perhaps update the docs on error_messages_for so its explicitly stated that it will not html escape any characters that require it in an error message.
-
DHH
Ah, I follow. That makes sense. If you wrap this up with as a proper patch and update any tests needed, it's going in.
-
Inge Jørgensen
Ran into this today, here's a patch. The diff posted breaks the test, I had to explicitely state ERB::Util.html_escape(msg).
-
Zach Dennis
Inge, can you re-post patch with corresponding test cases ?
-
Inge Jørgensen
Certainly. Something like this?
-
Yaroslav Markin
If applying this, we should probably also patch
error_message_on. That isactive_record_helper.rb@L123@ -
Dan Barry
I've attached the corresponding patch for error_message_on.
Also tested that Inge's patch still applies cleanly, and it does.
-
Repository
- State changed from new to resolved
- Tag changed from actionview, errors to actionview, errors, patch
(from [45494580d9405e80ba124d17c8379436883c8c78]) Ensure Active Record error related view helpers escape the message [#1280 error_messages_for doesn't html escape it's messages state:resolved] [Inge Jørgensen, Dan Barry]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
