Skip to content

Instantly share code, notes, and snippets.

@gkra
Created June 2, 2015 23:46
Show Gist options
  • Save gkra/64e19568600c9782265d to your computer and use it in GitHub Desktop.
Save gkra/64e19568600c9782265d to your computer and use it in GitHub Desktop.
irb(main):022:0> url = 'https://a.b.c:1234/'
=> "https://a.b.c:1234/"
irb(main):023:0> unless url.match(%r{/vco/api$}) ? true : false
irb(main):024:1> url.gsub!(%r{/?$}, '/vco/api')
irb(main):025:1> end
=> "https://a.b.c:1234/vco/api/vco/api"
@shadoi
Copy link

shadoi commented Jun 2, 2015

try %r{\A/.*\z} instead in your gsub

@shadoi
Copy link

shadoi commented Jun 2, 2015

also, use URI.parse and only perform matches on the path to avoid nasty injection vulnerabilities

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment