Skip to content

Commit

Permalink
add Url Component encoding decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
lublak committed Sep 12, 2023
1 parent 86d25b1 commit 5f8121f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ Features:
- see icon-v (utf8, base64, utf16, etc...)
- with strip/add BOM
- Decode Entities
- Url
- Url
- Url Component
- Xml
- Legacy
- Strict
- Html
- Legacy
- Strict
- Encode Entities
- Url
- Url
- Url Component
- Xml
- Extensive
- UTF8
Expand Down
64 changes: 39 additions & 25 deletions nodes/TextManipulation/TextManipulation.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ function charsTrim(str: string, chars: string) {
*/
function unescapeEscapedCharacters(str: string) {
/*eslint-disable */
const escapeCharacters: Record<string, string> = {
'\\0': '\0',
"\\'": "'",
'\\"': '"',
'\\\\': '\\',
'\\n': '\n',
'\\r': '\r',
'\\v': '\v',
'\\t': '\t',
'\\b': '\b',
'\\f': '\f',
};
/*eslint-enable */
const escapeCharacters: Record<string, string> = {
'\\0': '\0',
"\\'": "'",
'\\"': '"',
'\\\\': '\\',
'\\n': '\n',
'\\r': '\r',
'\\v': '\v',
'\\t': '\t',
'\\b': '\b',
'\\f': '\f',
};
/*eslint-enable */

return str.replace(
/(\\0|\\'|\\"|\\n|\\r|\\v|\\t|\\b|\\f)|\\u([\da-fA-F]{4})|\\x([\da-fA-F]{2})|\\u{(0*(?:10|[\da-fA-F])?[\da-fA-F]{1,4})}|\\(.)/g,
Expand Down Expand Up @@ -651,6 +651,10 @@ export class TextManipulation implements INodeType {
},
type: 'options',
options: [
{
name: 'Html',
value: 'html',
},
{
name: 'Nothing',
value: 'nothing',
Expand All @@ -660,12 +664,12 @@ export class TextManipulation implements INodeType {
value: 'url',
},
{
name: 'Xml',
value: 'xml',
name: 'Url Component',
value: 'urlComponent',
},
{
name: 'Html',
value: 'html',
name: 'Xml',
value: 'xml',
},
],
default: 'nothing',
Expand Down Expand Up @@ -726,6 +730,10 @@ export class TextManipulation implements INodeType {
},
type: 'options',
options: [
{
name: 'Html',
value: 'html',
},
{
name: 'Nothing',
value: 'nothing',
Expand All @@ -735,12 +743,12 @@ export class TextManipulation implements INodeType {
value: 'url',
},
{
name: 'Xml',
value: 'xml',
name: 'Url Component',
value: 'urlComponent',
},
{
name: 'Html',
value: 'html',
name: 'Xml',
value: 'xml',
},
],
default: 'nothing',
Expand Down Expand Up @@ -1454,6 +1462,9 @@ export class TextManipulation implements INodeType {
case 'url':
text = decodeURI(text);
break;
case 'urlComponent':
text = decodeURIComponent(text);
break;
case 'xml':
switch (manipulation.entitiesDecodeMode) {
case 'legacy':
Expand Down Expand Up @@ -1500,6 +1511,9 @@ export class TextManipulation implements INodeType {
case 'url':
text = encodeURI(text);
break;
case 'urlComponent':
text = encodeURIComponent(text);
break;
case 'xml':
switch (manipulation.entitiesEncodeMode) {
case 'extensive':
Expand Down Expand Up @@ -1769,7 +1783,7 @@ export class TextManipulation implements INodeType {
}
break;
case 'pad':
if (manipulation.targetLength == null || manipulation.targetLength < 0)
if (manipulation.targetLength == null || (manipulation.targetLength as number) < 0)
throw new NodeOperationError(
this.getNode(),
'The Target Length has to be set to at least 0 or higher!',
Expand Down Expand Up @@ -1808,14 +1822,14 @@ export class TextManipulation implements INodeType {
);
break;
case 'length':
if (manipulation.endLength == null || manipulation.endLength < 0) {
if (manipulation.endLength == null || (manipulation.endLength as number) < 0) {
throw new NodeOperationError(
this.getNode(),
'The Length has to be set to at least 0 or higher!',
{ itemIndex },
);
}
if ((manipulation.startPosition || 0) < 0)
if (((manipulation.startPosition as number | null) || 0) < 0)
text = text.substring(
manipulation.startPosition as number,
text.length +
Expand All @@ -1837,7 +1851,7 @@ export class TextManipulation implements INodeType {
}
break;
case 'repeat':
if (manipulation.times == null || manipulation.times < 0)
if (manipulation.times == null || (manipulation.times as number) < 0)
throw new NodeOperationError(
this.getNode(),
'The Times has to be set to at least 0 or higher!',
Expand Down

0 comments on commit 5f8121f

Please sign in to comment.