Regex auto-escape

18 views
Skip to first unread message

Ugo Bellavance

unread,
Jan 12, 2017, 2:23:48 PM1/12/17
to Puppet Users
Hi,

I've been working on a public module that manage text entries that have SELinux contexts in them. I added basic support to some of the regex special characters that may be used in SELinux contexts and here's the result: https://github.com/ubellavance/puppet-selinux/blob/deleteworks/manifests/fcontext.pp#L49-L50.  After having done something that fits my need up to now, I knew that it was probably not perfect so I looked at some lists of contexts and found out that there are a lot more than just "(/.*)" entries but I think it doesn't make sense to do a regsubst for every special character.  Is there something that can be done directly in the module that would automatically put a backspace before every regex special character?

Thanks,

Thomas Müller

unread,
Jan 13, 2017, 6:24:57 AM1/13/17
to Puppet Users


Am Donnerstag, 12. Januar 2017 20:23:48 UTC+1 schrieb Ugo Bellavance:
Hi,

I've been working on a public module that manage text entries that have SELinux contexts in them. I added basic support to some of the regex special characters that may be used in SELinux contexts and here's the result: https://github.com/ubellavance/puppet-selinux/blob/deleteworks/manifests/fcontext.pp#L49-L50.  After having done something that fits my need up to now, I knew that it was probably not perfect so I looked at some lists of contexts and found out that there are a lot more than just "(/.*)" entries but I think it doesn't make sense to do a regsubst for every special character.  Is there something that can be done directly in the module that would automatically put a backspace before every regex special character?

 
maybe the shellwords does it for you: http://ruby-doc.org/stdlib-2.0.0/libdoc/shellwords/rdoc/Shellwords.html

 
instead of working on your own selinux module I'd invite you to parcitipate on the voxpupuli/selinux module: https://github.com/voxpupuli/puppet-selinux

- Thomas

Ugo Bellavance

unread,
Jan 13, 2017, 7:24:12 AM1/13/17
to Puppet Users
Thanks for your answer. The selinux module is actually from camptocamp. Mine is a fork, but you're right, I should test voxpopuli'.  At the time at which I needed an SELinux module, I needed SELinux ports support, which, I think, wasn't supported by voxpopul's (or its ancestor), so I chose camptocamp's. I realize that I "lost" many hours to improve camptocamp's module while a switch to voxpopuli was the right thing to do.  At least it gave me more experience with contributing to puppet modules.  camptocamp's module is simpler than voxpopuli, so it's more accessible to me.

Now I have some testing to do :).

Thanks!
Reply all
Reply to author
Forward
0 new messages