Skip to content
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

sets script_name to always be a string. #17616

Closed

Conversation

JONBRWN
Copy link
Contributor

@JONBRWN JONBRWN commented Nov 14, 2014

see issue: #17615
and commit: 8cbcd19
which states script_name should always return a string
when script_name is nil in the options hash, script_name is set to nil.

options = {script_name: nil}
script_name = options.delete(:script_name) {‘’} # => nil

see issue: rails#17615

when script_name is nil in the options hash, script_name is set to nil.

options = {script_name: nil}
script_name = options.delete(:script_name) {‘’} # => nil
@egilburg
Copy link
Contributor

I guess it can just be options.delete(:script_name) || '' then?

@JONBRWN
Copy link
Contributor Author

JONBRWN commented Nov 14, 2014

@egilburg Yeah, that's what I did in my pull request

@egilburg
Copy link
Contributor

@JONBRWN I see the following diff

options.delete(:script_name) { '' } || ''

Whereas I think it can be simplified to:

options.delete(:script_name) || ''

Since you are always assigning '' on nil, whether explicit value for key or due to missing key, you don't need to also use the missing-key default of { '' }

@JONBRWN
Copy link
Contributor Author

JONBRWN commented Nov 14, 2014

@egilburg you are correct, long day! Will edit the pull request when I get home

@sandipransing
Copy link
Contributor

think of using #fetch instead of #delete

options.fetch(:script_name) { '' }

@jGRUBBS
Copy link

jGRUBBS commented Nov 14, 2014

@sandipransing #fetch does not achieve the desired result. :script_name should be removed from options and should always return a String and never a nil

@egilburg's solution should be accepted:

options.delete(:script_name) || ''

@jGRUBBS
Copy link

jGRUBBS commented Nov 19, 2014

@tenderlove what do you think? Seeing as you refactored this method in 8cbcd19

@tenderlove
Copy link
Member

Seems like a reasonable change, but let me make sure the tests are OK first.

@arthurnn
Copy link
Member

dont we need a regression test for this too?

@JONBRWN
Copy link
Contributor Author

JONBRWN commented Nov 22, 2014

@tenderlove @arthurnn let me know if there's something I can do on my part with the testing

@rafaelfranca
Copy link
Member

@JONBRWN we need a test for sure.

@rafaelfranca rafaelfranca added this to the 4.2.0 milestone Nov 24, 2014
@dhh dhh assigned dhh and tenderlove and unassigned dhh Nov 25, 2014
spastorino pushed a commit that referenced this pull request Nov 25, 2014
Closes #17615 #17616

when script_name is nil in the options hash, script_name is set to nil.

options = {script_name: nil}
script_name = options.delete(:script_name) {‘’} # => nil

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
@spastorino
Copy link
Contributor

Closed by 1e5290a

@spastorino spastorino closed this Nov 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants