Skip to content
This repository was archived by the owner on Dec 18, 2020. It is now read-only.

Commit bd8d37d

Browse files
committed
Encode/Decode URI component can throw exceptions
1 parent 8b2dfdb commit bd8d37d

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

src/Global.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* globals exports */
22
"use strict";
33

4-
// module Global
5-
64
exports.nan = NaN;
75

86
exports.isNaN = isNaN;
@@ -18,8 +16,3 @@ exports.readInt = function (radix) {
1816
};
1917

2018
exports.readFloat = parseFloat;
21-
22-
exports.decodeURI = decodeURI;
23-
exports.encodeURI = encodeURI;
24-
exports.decodeURIComponent = decodeURIComponent;
25-
exports.encodeURIComponent = encodeURIComponent;

src/Global.purs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,3 @@ foreign import readInt :: Int -> String -> Number
1919

2020
-- | Parse a floating point value from a `String`
2121
foreign import readFloat :: String -> Number
22-
23-
-- | uri decoding
24-
foreign import decodeURI :: String -> String
25-
26-
-- | uri encoding
27-
foreign import encodeURI :: String -> String
28-
29-
-- | uri component decoding
30-
foreign import decodeURIComponent :: String -> String
31-
32-
-- | uri component encoding
33-
foreign import encodeURIComponent :: String -> String

src/Global/Unsafe.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* globals exports, JSON */
22
"use strict";
33

4-
// module Global.Unsafe
5-
64
exports.unsafeStringify = function (x) {
75
return JSON.stringify(x);
86
};
@@ -25,3 +23,7 @@ exports.unsafeToPrecision = function (digits) {
2523
};
2624
};
2725

26+
exports.unsafeDecodeURI = decodeURI;
27+
exports.unsafeEncodeURI = encodeURI;
28+
exports.unsafeDecodeURIComponent = decodeURIComponent;
29+
exports.unsafeEncodeURIComponent = encodeURIComponent;

src/Global/Unsafe.purs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,38 @@ module Global.Unsafe where
44
-- | to serialize functions returns undefined
55
foreign import unsafeStringify :: forall a. a -> String
66

7-
-- | Formats Number as a String with limited number of digits after the dot
7+
-- | Formats Number as a String with limited number of digits after the dot.
8+
-- |
89
-- | May throw RangeError if the number of digits is not within the allowed range
910
-- | (standard precision range is 0 to 20, but implementations may change it)
1011
foreign import unsafeToFixed :: Int -> Number -> String
1112

1213
-- | Formats Number as String in exponential notation limiting number of digits
13-
-- | after the decimal dot.
14+
-- | after the decimal dot.
15+
-- |
1416
-- | May throw RangeError if the number of digits is not within the allowed range
1517
-- | (standard precision range is 0 to 20, but implementations may change it)
1618
foreign import unsafeToExponential :: Int -> Number -> String
1719

18-
-- | Formats Number as String in fixed-point or exponential notation rounded
20+
-- | Formats Number as String in fixed-point or exponential notation rounded
1921
-- | to specified number of significant digits.
22+
-- |
2023
-- | May throw RangeError if the number of digits is not within the allowed range
2124
-- | (standard precision range is 0 to 100, but implementations may change it)
2225
foreign import unsafeToPrecision :: Int -> Number -> String
26+
27+
-- | URI decoding. May throw a `URIError` if given a value with undecodeable
28+
-- | escape sequences.
29+
foreign import unsafeDecodeURI :: String -> String
30+
31+
-- | URI encoding. May throw a `URIError` if given a value with unencodeable
32+
-- | characters.
33+
foreign import unsafeEncodeURI :: String -> String
34+
35+
-- | URI component decoding. May throw a `URIError` if given a value with
36+
-- | undecodeable escape sequences.
37+
foreign import unsafeDecodeURIComponent :: String -> String
38+
39+
-- | URI component encoding. May throw a `URIError` if given a value with
40+
-- | unencodeable characters.
41+
foreign import unsafeEncodeURIComponent :: String -> String

0 commit comments

Comments
 (0)