Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

url encode

  • Loading branch information...
commit d3245adad0f242fec1ccfb7e630c6c39f36c359d 1 parent 68391a4
Kyle Roche kyleroche authored

Showing 1 changed file with 38 additions and 0 deletions. Show diff stats Hide diff stats

  1. +38 0 scripts/url.coffee
38 scripts/url.coffee
... ... @@ -0,0 +1,38 @@
  1 +# Description:
  2 +# URL encoding and decoding
  3 +#
  4 +# Dependencies:
  5 +# None
  6 +#
  7 +# Configuration:
  8 +# None
  9 +#
  10 +# Commands:
  11 +# hubot url encode|decode <query> - URL encode or decode <string>
  12 +# hubot url form encode|decode <query> - URL form-data encode or decode <string>
  13 +#
  14 +# Author:
  15 +# jimeh
  16 +
  17 +module.exports = (robot) ->
  18 + robot.respond /URL encode( me)? (.*)/i, (msg) ->
  19 + msg.send encodeURIComponent(msg.match[2])
  20 +
  21 + robot.respond /URL decode( me)? (.*)/i, (msg) ->
  22 + msg.send decodeURIComponent(msg.match[2])
  23 +
  24 + robot.respond /URL form encode( me)? (.*)/i, (msg) ->
  25 + msg.send urlFormEncode(msg.match[2])
  26 +
  27 + robot.respond /URL form decode( me)? (.*)/i, (msg) ->
  28 + msg.send urlFormDecode(msg.match[2])
  29 +
  30 +# url form-data encoding helpers (partially ripped from jshashes npm package)
  31 +urlFormEncode = (str) ->
  32 + escape(str)
  33 + .replace(new RegExp('\\+','g'),'%2B')
  34 + .replace(new RegExp('%20','g'),'+')
  35 +
  36 +urlFormDecode = (str) ->
  37 + unescape(str.replace(new RegExp('\\+','g'), ' '))
  38 +

0 comments on commit d3245ad

Please sign in to comment.
Something went wrong with that request. Please try again.