Skip to content

Commit

Permalink
Dev: Use safe decodeUriComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Mar 28, 2018
1 parent 63010b3 commit 92d4530
Show file tree
Hide file tree
Showing 4 changed files with 1,066 additions and 250 deletions.
71 changes: 71 additions & 0 deletions doc/UTIL_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,20 @@ dateFormat('yyyy-mm-dd HH:MM:ss'); // -> 2016-11-19 19:00:04
dateFormat(new Date(), 'yyyy-mm-dd'); // -> 2016-11-19
```

## decodeUriComponent

Better decodeURIComponent that does not throw if input is invalid.

|Name |Type |Desc |
|------|------|----------------|
|str |string|String to decode|
|return|string|Decoded string |

```javascript
decodeUriComponent('%%25%'); // -> '%%%'
decodeUriComponent('%E0%A4%A'); // -> '\xE0\xA4%A'
```

## defaults

Fill in undefined properties in object with the first value present in the following list of defaults objects.
Expand Down Expand Up @@ -2244,6 +2258,35 @@ type(function () {}); // -> 'function'
type([]); // -> 'array'
```

## ucs2

UCS-2 encoding and decoding.

### encode

Create a string using an array of code point values.

|Name |Type |Desc |
|------|------|--------------------|
|arr |array |Array of code points|
|return|string|Encoded string |

### decode

Create an array of code point values using a string.

|Name |Type |Desc |
|------|------|--------------------|
|str |string|Input string |
|return|array |Array of code points|

```javascript
ucs2.encode([0x61, 0x62, 0x63]); // -> 'abc'
ucs2.decode('abc'); // -> [0x61, 0x62, 0x63]
'𝌆'.length; // -> 2
ucs2.decode('𝌆').length; // -> 1
```

## uniqId

Generate a globally-unique id.
Expand Down Expand Up @@ -2284,6 +2327,34 @@ Convert the first character of string to upper case.
upperFirst('red'); // -> Red
```

## utf8

UTF-8 encoding and decoding.

### encode

Turn any UTF-8 decoded string into UTF-8 encoded string.

|Name |Type |Desc |
|------|------|----------------|
|str |string|String to encode|
|return|string|Encoded string |

### decode

|Name |Type |Desc |
|------------|-------|----------------------|
|str |string |String to decode |
|[safe=false]|boolean|Suppress error if true|
|return |string |Decoded string |

Turn any UTF-8 encoded string into UTF-8 decoded string.

```javascript
utf8.encode('\uD800\uDC00'); // -> '\xF0\x90\x80\x80'
utf8.decode('\xF0\x90\x80\x80'); // -> '\uD800\uDC00'
```

## values

Create an array of the own enumerable property values of object.
Expand Down
11 changes: 3 additions & 8 deletions src/Resources/Resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
isErudaEl,
toArr,
concat,
rmCookie
rmCookie,
decodeUriComponent
} from '../lib/util';

export default class Resources extends Tool
Expand Down Expand Up @@ -170,13 +171,7 @@ export default class Resources extends Tool
each(document.cookie.split(';'), function (val, t)
{
val = val.split('=');
try
{
t = decodeURIComponent(val[1]);
} catch(e)
{
t = val[1];
}
t = decodeUriComponent(val[1]);
cookieData.push({
key: trim(val[0]),
val: t
Expand Down
Loading

0 comments on commit 92d4530

Please sign in to comment.