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

Implemented a new feature that Hashie::Mash.load accepts a Pathname object #331 #337

Closed
wants to merge 2 commits into from

Conversation

gipcompany
Copy link
Contributor

@dblock
Copy link
Member

dblock commented Dec 28, 2015

This code is good.

I want to leave this open for others to comment, in theory the caller can just do to_s on the Pathname and we won't need this merged. I don't see many gems supporting Pathname directly, I am not convinced we should.

@gipcompany
Copy link
Contributor Author

@dblock thank you very much for taking your time to review the code. I hope to see others' feedbacks or opinions.

@gregory
Copy link
Contributor

gregory commented Jan 14, 2016

@gipcompany why do you feel that we need to be able to handle Pathname objects instead of a plain string?
Can't you just do Mash.load(Pathname('your_path').to_s) ?

@michaelherold
Copy link
Member

The only thing I'm not a fan of is the switching based on class. An alternative to this would be to just always call #to_s on the parameter, a la:

@file_path = file_path.to_s

This doesn't break the current implementation and allows you to use Pathname or any other type of file pointer that responds to #to_s. Since we're expecting a string here anyway, it's semantically the same but expands the usable parameter space.

@dblock
Copy link
Member

dblock commented Feb 1, 2016

The issue with things like to_s is that you start opening files by passing garbage in, and that is bound to give us some security issues somewhere in a stack of things at some point.

@najamelan
Copy link

To bad this didn't get merged. I subclass Mash just to get this... o well.

I also don't understand the argument about passing garbage in. If it resolves to an existing filename, then apparently it isn't garbage, and in the end the user chooses what they pass in... and as far as I'm concerned it's their responsibility not to pass in "garbage" that resolves to "/etc/shadow". In any case files here should be opened read only, so what's the security implication?

I think it makes sense that code that operates on files can at least take in Pathname instead of a string. But personally why not everything that responds to #to_str, since it's up to the user to send something sensible in. If you want to be sure that it is a path, and not garbage, it's a small fix:

path.kind_of?( Pathname ) and path = path.to_s

@@ -4,8 +4,10 @@
* [#319](https://github.com/intridea/hashie/pull/319): Fix a regression from 3.4.1 where `Hashie::Extensions::DeepFind` is no longer indifference-aware - [@michaelherold](https://github.com/michaelherold).
* [#240](https://github.com/intridea/hashie/pull/240): Fixed nesting twice with Clash keys - [@bartoszkopinski](https://github.com/bartoszkopinski).
* [#322](https://github.com/intridea/hashie/pull/322): Fixed `reverse_merge` issue with `Mash` subclasses - [@marshall-lee](https://github.com/marshall-lee).
* [#337](https://github.com/intridea/hashie/pull/337): Implemented a new feature that Hashie::Mash.load accepts a Pathname object #331 - [@gipcompany](https://github.com/gipcompany).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should just say Hashie::Mash.load accepts a Pathname, remove "implemented a new feature" and "object", quote everything that's code.

@dblock
Copy link
Member

dblock commented Jul 14, 2016

@najamelan I think you're right, and I am ok with the code as it stands. @michaelherold LMK how you feel about this?

file_path.is_a?(Pathname) ? file_path.to_s : file_path

@dblock
Copy link
Member

dblock commented Jul 14, 2016

This should be rebased, build fixed.

@michaelherold
Copy link
Member

LGTM. 👍

@dblock
Copy link
Member

dblock commented Jul 14, 2016

@gipcompany sorry for the delay, see above, would appreciate if you could help wrap this up

@najamelan
Copy link

@dblock Thanks

@gipcompany
Copy link
Contributor Author

@dblock let me see. I would like to catch up with the current status. Should I resolve this PR not to be conflicted and re-push it?

@dblock
Copy link
Member

dblock commented Jul 15, 2016

Lets fix the build. ActiveSupport 5 is in the way now I think with older rubies, just add ~> 4.x into https://github.com/intridea/hashie/blob/master/Gemfile#L15 for now, that should fix it.

@@ -12,7 +12,7 @@ scheme are considered to be bugs.

### Added

* Nothing yet.
* [#337](https://github.com/intridea/hashie/pull/337): Implemented a new feature that Hashie::Mash.load accepts a Pathname object #331 - [@gipcompany](https://github.com/gipcompany).
Copy link
Member

@dblock dblock Jul 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should say "Hashie::Mash.load accepts a Pathname - ...". This is too verbose otherwise :)

@dblock
Copy link
Member

dblock commented Jul 15, 2016

Try to rebase this against master. You should end up with a single commit here. Git can be fun.

@dblock
Copy link
Member

dblock commented Jul 15, 2016

Merged via bbafade.

@dblock dblock closed this Jul 15, 2016
@gipcompany
Copy link
Contributor Author

Wow, this being merged in public is my first time experience. Thank you everyone for each support and thank you, @dblock for your continuous support.

@dblock
Copy link
Member

dblock commented Jul 15, 2016

Also hashes in commits that contain dictionary words, like fade in bbafade are a big deal, congrats on your first open source contribution!

@najamelan
Copy link

najamelan commented Jul 18, 2016

I'm sorry to arrive a bit late with this, but as I'm implementing something similar, I came to the following conclusion:

Pathname, File, but also Dir all implement #to_path which gives the string path... In some sense it seems more logical to check for objects responding to #to_path and to use that instead of #to_s. It would require a check for directory? if you don't support loading all files in a directory though.

@dblock
Copy link
Member

dblock commented Jul 18, 2016

You have some good points @najamelan, feel free to PR an update!

@gipcompany gipcompany deleted the 331_new_feature branch July 23, 2016 04:44
jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Oct 15, 2016
[3.4.6]: hashie/hashie@v3.4.5...v3.4.6

### Fixed

* [#368](hashie/hashie#368): Since `hashie/mash` can be required alone, require its dependencies - [@jrafanie](https://github.com/jrafanie).

## [3.4.5] - 2016-09-16

[3.4.5]: hashie/hashie@v3.4.4...v3.4.5

### Added

* [#337](hashie/hashie#337), [#331](hashie/hashie#331): `Hashie::Mash#load` accepts a `Pathname` object - [@gipcompany](https://github.com/gipcompany).

### Deprecated

* [#366](hashie/hashie#366): Hashie is no longer tested on Ruby < 2 - [@dblock](https://github.com/dblock).

### Fixed

* [#358](hashie/hashie#358): Fixed support for Array#dig - [@modosc](https://github.com/modosc).
* [#365](hashie/hashie#365): Ensured ActiveSupport::HashWithIndifferentAccess is defined before use in #deep_locate  - [@mikejarema](https://github.com/mikejarema).

### Miscellanous

* [#366](hashie/hashie#366): Added Danger, PR linter - [@dblock](https://github.com/dblock).

## [3.4.4] - 2016-04-29

[3.4.4]: hashie/hashie@v3.4.3...v3.4.4

### Added

* [#349](hashie/hashie#349): Convert `Hashie::Mash#dig` arguments for Ruby 2.3.0 - [@k0kubun](https://github.com/k0kubun).

### Fixed

* [#240](hashie/hashie#240): Fixed nesting twice with Clash keys - [@bartoszkopinski](https://github.com/bartoszkopinski).
* [#317](hashie/hashie#317): Ensure `Hashie::Extensions::MethodQuery` methods return boolean values - [@michaelherold](https://github.com/michaelherold).
* [#319](hashie/hashie#319): Fix a regression from 3.4.1 where `Hashie::Extensions::DeepFind` is no longer indifference-aware - [@michaelherold](https://github.com/michaelherold).
* [#322](hashie/hashie#322): Fixed `reverse_merge` issue with `Mash` subclasses - [@marshall-lee](https://github.com/marshall-lee).
* [#346](hashie/hashie#346): Fixed `merge` breaking indifferent access - [@docwhat](https://github.com/docwhat), [@michaelherold](https://github.com/michaelherold).
* [#350](hashie/hashie#350): Fixed from string translations used with `IgnoreUndeclared` - [@marshall-lee](https://github.com/marshall-lee).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants