Commit 8336a3b7 authored by Jamie Tanna's avatar Jamie Tanna

Document one-liner for URL decoding

Closes #506.
parent f564a9e8
Pipeline #64183019 passed with stages
in 5 minutes and 39 seconds
---
title: URL Decoding with Ruby on the Command Line
description: How to use Ruby's standard library to decode URLs with a handy one-liner.
categories:
- blogumentation
tags:
- blogumentation
- ruby
- cli
date: 2019-05-31T21:58:11+0100
license_prose: CC-BY-NC-SA-4.0
license_code: Apache-2.0
slug: url-decode-ruby-cli
---
When working with URLs that contain other URLs (such as a `redirect_uri` in an OAuth2 authorization request), you may get annoyed when you can't decode the encoded URL, **??**.
Following the advice from [this Stack Overflow answer](https://stackoverflow.com/a/7146153/2257038), we can use `CGI.unescape`, and create a nice command-line one-liner:
```sh
ruby -rcgi -e 'puts CGI.unescape(ARGF.read)'
```
This lets us i.e. run:
```sh
$ echo 'https%3A%2F%2Fwww.jvt.me' | ruby -rcgi -e 'puts CGI.unescape(ARGF.read)'
https://www.jvt.me
```
---
posts:
- https://www.jvt.me/posts/2019/05/31/url-decode-ruby-cli/
- https://www.jvt.me/posts/2019/05/26/why-wwwjvtme/
- https://www.jvt.me/posts/2019/05/26/hugo-render/
- https://www.jvt.me/posts/2019/05/22/ical-events-hugo/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment