Skip to content

Commit

Permalink
fix decode_url
Browse files Browse the repository at this point in the history
  • Loading branch information
unytics committed Oct 24, 2023
1 parent 7415c2a commit e5b605e
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions bigfunctions/decode_url.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
type: function_sql
type: function_js
category: transform_string
author:
name: "Credits: Mikhail Berlyant"
url: https://www.linkedin.com/in/berlyant/
avatar_url: "https://media.licdn.com/dms/image/C5603AQE6NRsrZTk-Bg/profile-displayphoto-shrink_200_200/0/1545354261200?e=1703721600&v=beta&t=s3YOHI-t5OWd2ql-z-e1nmC9CPFHTWhYeYKssYZtIpo"
name: Paul Marcombes
url: https://www.linkedin.com/in/paul-marcombes
avatar_url: "https://lh3.googleusercontent.com/a-/ACB-R5RDf2yxcw1p_IYLCKmiUIScreatDdhG8B83om6Ohw=s260"
description: |-
Decode url encoded string
*(inspired from [this stackoverflow answer](https://stackoverflow.com/questions/13831391/bigquery-url-decode))*
Decode `url_encoded_string`
arguments:
- name: url_encoded_string
type: string
Expand All @@ -18,11 +17,4 @@ examples:
arguments:
- "'http%3A%2F%2Fwww.example.com%2Fhello%3Fv%3D12345'"
output: "http://www.example.com/hello?v=12345"
code: |
(
select safe_convert_bytes_to_string(
array_to_string(array_agg(
if(starts_with(y, '%'), from_hex(substr(y, 2)), cast(y as bytes)) order by i
), b''))
from unnest(regexp_extract_all(url, r"%[0-9a-fa-f]{2}|[^%]+")) as y with offset as i
)
code: return decodeURI(url_encoded_string);

0 comments on commit e5b605e

Please sign in to comment.