Project

General

Profile

Misc #15294

Add warnings for invalid ERB trim modes

Added by jsc (Justin Collins) 11 days ago. Updated 8 days ago.

Status:
Closed
Priority:
Normal
[ruby-core:89762]

Description

Currently, the ERB library will accept any value for the "trim mode". If the trim mode is any string containing %, -, >, <> or an integer 0-2, the appropriate trim mode will be set. If not, no exception or warning is raised.

I had a bug in Brakeman for 1.5 years because I was passing the wrong value as the trim mode. Since the value coincidentally contained - on my test machine, I didn't notice until yesterday.

The attached patch proposes reporting a warning if an invalid trim mode is provided. It does allow a couple invalid modes (you could provide duplicate or conflicting values, like %% or <>>), but I think this is still an improvement over accepting any value at all.

If there is interest, I could spend some time to make it even more strict.

I set the uplevel to 5, which is right if a user is calling ERB.new (most common case?). I don't know if that is the correct approach.

In the future, perhaps this should be an exception instead of a warning.

erb_trim_mode_warning.patch (1.41 KB) erb_trim_mode_warning.patch Add warnings for invalid ERB trim modes jsc (Justin Collins), 11/09/2018 09:02 PM

Associated revisions

Revision ab5a3db4
Added by k0kubun (Takashi Kokubun) 9 days ago

erb.rb: warn invalid trim_mode [Misc #15294]

From: Justin Collins justin@presidentbeef.com

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 65671
Added by k0kubun (Takashi Kokubun) 9 days ago

erb.rb: warn invalid trim_mode [Misc #15294]

From: Justin Collins justin@presidentbeef.com

Revision 8ad336b5
Added by nobu (Nobuyoshi Nakada) 8 days ago

Adopt [Misc #15294]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

#1 Updated by k0kubun (Takashi Kokubun) 9 days ago

  • Status changed from Open to Closed

Applied in changeset trunk|r65671.


erb.rb: warn invalid trim_mode [Misc #15294]

From: Justin Collins justin@presidentbeef.com

#2 [ruby-core:89772] Updated by k0kubun (Takashi Kokubun) 9 days ago

I thought warning message should provide information that helps to fix the warning, so I modified your patch but applied that in r65671. Thanks.

#3 [ruby-core:89776] Updated by jsc (Justin Collins) 8 days ago

Thank you!

Also available in: Atom PDF