Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Better regular expressions for mountpoint paths. #8

Merged
merged 1 commit into from
Mar 3, 2015
Merged

Conversation

gaylatea
Copy link
Contributor

This changeset modifies the mountpoint regular expressions which determine absolute paths, to not error out in a couple of cases that I could find. I was trying to use two-character directory names - to wit, /var/lib/pg/data - and this regex was choking on them.

I've tried to make a general solution that works for all the forms of expressing a path.

@puppetcla
Copy link

Waiting for CLA signature by @silversupreme

@silversupreme - We require a Contributor License Agreement (CLA) for people who contribute to Puppet, but we have an easy click-through license with instructions, which is available at https://cla.puppetlabs.com/

Note: if your contribution is trivial and you think it may be exempt from the CLA, please post a short reply to this comment with details. http://docs.puppetlabs.com/community/trivial_patch_exemption.html

@gaylatea
Copy link
Contributor Author

I'm pretty sure this is a trivial change under your guidelines - it's a one-line change that updates two regular expressions. No real creative endeavour went into its creation. 😄

@gaylatea
Copy link
Contributor Author

Hello there! Any updates on merging this? It's a simple change but it's pretty useful, and I'd like to not have to point my Puppetfile at my fork. 😺

@elyscape
Copy link

Someone in #puppet encountered this same issue earlier today. Could we get an update on this pull request?

@gaylatea
Copy link
Contributor Author

If it helps, I just signed the CLA online. I had hoped that this would be small enough to not need it but there you are. 😺

@@ -37,7 +37,7 @@
validate do |value|
raise Puppet::Error, "name is not allowed to contain whitespace" if value =~ /\s/
raise Puppet::Error, "name is not allowed to have trailing slashes" if value =~ %r{/$}
raise Puppet::Error, "name must be an absolute path" if value =~ %r{^[^/]} or value =~ %r{/../}
raise Puppet::Error, "name must be an absolute path" if ((value =~ /^[^\/]/) == 0) or ((value =~ %r{/\.\./}) == 0)

Choose a reason for hiding this comment

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

These should have been left without == 0. The first regular expression already restricts itself to the beginning of the string with ^ and the second regular expression should be allowed to match anywhere in the string. You don't want to let /mnt/location/../otherlocation through, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How does this look, as an alternative form?

(value !~ /^\// or value =~ /\/\.{2}\//)

Choose a reason for hiding this comment

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

The fewer unnecessary changes the better. I'd go with:

raise Puppet::Error, "name must be an absolute path" if value =~ %r{^[^/]} or value =~ %r{/\.\./}

This should not choke on small directory names, like "pg".

Thanks to @elyscape for pointing out a better way of doing this.
@gaylatea
Copy link
Contributor Author

@elyscape I've rewritten this and rebased to make the history cleaner. Your version works with all the tests I do. Thank you for your recommendation here. 😺

@elyscape
Copy link

Pinging some maintainers (@mhaskel, @hunner, @jeffmccune): any updates on merging this?

underscorgan pushed a commit that referenced this pull request Mar 3, 2015
Better regular expressions for mountpoint paths.
@underscorgan underscorgan merged commit 76fc4aa into puppetlabs-toy-chest:master Mar 3, 2015
@underscorgan
Copy link
Contributor

Thanks for the contribution @silversupreme, and sorry for the delay! We've removed the CLA bot from modules, and yes, this would've been considered 'trivial' anyways.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants