Skip to content

Commit e44a4de

Browse files
committed
chore: lint fix
1 parent 9b209ef commit e44a4de

File tree

12 files changed

+83
-87
lines changed

12 files changed

+83
-87
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
jobs:
1616
scan:
1717
permissions:
18-
packages: write
18+
packages: write
1919
contents: write # publish sbom to GH releases/tag assets
2020
runs-on: ubuntu-latest
2121
steps:
@@ -74,14 +74,14 @@ jobs:
7474
- name: Checkout code
7575
uses: actions/checkout@v4
7676
with:
77-
fetch-depth: 0
77+
fetch-depth: 0
7878

7979
- name: Setup Node.js
8080
uses: actions/setup-node@v4
8181
with:
8282
node-version: 20.9.0
8383
registry-url: 'https://registry.npmjs.org'
84-
84+
8585
- name: Install
8686
run: npm ci
8787

@@ -92,4 +92,3 @@ jobs:
9292
run: npm publish --no-git-checks --provenance --tag ${{ github.sha }}
9393
env:
9494
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
95-

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
id: core_tag_and_release
5353
with:
5454
tag: v${{ env.TAG }}
55-
name: "httpsnippet v${{ env.TAG }} 📦"
55+
name: 'httpsnippet v${{ env.TAG }} 📦'
5656
generateReleaseNotes: true
5757
prerelease: false
58-
draft: false
58+
draft: false

.github/workflows/sast.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ on:
44
pull_request: {}
55
push:
66
branches:
7-
- master
7+
- master
88
workflow_dispatch: {}
99

10-
1110
jobs:
1211
semgrep:
1312
name: Semgrep SAST

src/helpers/escape.test.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
11
import { escapeString } from './escape';
22

3-
describe('Escape methods', () => {
3+
describe('escape methods', () => {
44
describe('escapeString', () => {
55
it('does nothing to a safe string', () => {
6-
expect(
7-
escapeString("hello world")
8-
).toBe("hello world");
6+
expect(escapeString('hello world')).toBe('hello world');
97
});
108

119
it('escapes double quotes by default', () => {
12-
expect(
13-
escapeString('"hello world"')
14-
).toBe('\\"hello world\\"');
10+
expect(escapeString('"hello world"')).toBe('\\"hello world\\"');
1511
});
1612

1713
it('escapes newlines by default', () => {
18-
expect(
19-
escapeString('hello\r\nworld')
20-
).toBe('hello\\r\\nworld');
14+
expect(escapeString('hello\r\nworld')).toBe('hello\\r\\nworld');
2115
});
2216

2317
it('escapes backslashes', () => {
24-
expect(
25-
escapeString('hello\\world')
26-
).toBe('hello\\\\world');
18+
expect(escapeString('hello\\world')).toBe('hello\\\\world');
2719
});
2820

2921
it('escapes unrepresentable characters', () => {
3022
expect(
31-
escapeString('hello \u0000') // 0 = ASCII 'null' character
23+
escapeString('hello \u0000'), // 0 = ASCII 'null' character
3224
).toBe('hello \\u0000');
3325
});
3426
});

src/helpers/escape.ts

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,47 +31,45 @@ export interface EscapeOptions {
3131
* for the complete original algorithm.
3232
*/
3333
export function escapeString(rawValue: any, options: EscapeOptions = {}) {
34-
const {
35-
delimiter = '"',
36-
escapeChar = '\\',
37-
escapeNewlines = true
38-
} = options;
34+
const { delimiter = '"', escapeChar = '\\', escapeNewlines = true } = options;
3935

4036
const stringValue = rawValue.toString();
4137

42-
return [...stringValue].map((c) => {
43-
if (c === '\b') {
44-
return escapeChar + 'b';
45-
} else if (c === '\t') {
46-
return escapeChar + 't';
47-
} else if (c === '\n') {
48-
if (escapeNewlines) {
49-
return escapeChar + 'n';
50-
} else {
51-
return c; // Don't just continue, or this is caught by < \u0020
52-
}
53-
} else if (c === '\f') {
54-
return escapeChar + 'f';
55-
} else if (c === '\r') {
56-
if (escapeNewlines) {
57-
return escapeChar + 'r';
58-
} else {
59-
return c; // Don't just continue, or this is caught by < \u0020
60-
}
61-
} else if (c === escapeChar) {
62-
return escapeChar + escapeChar;
63-
} else if (c === delimiter) {
64-
return escapeChar + delimiter;
65-
} else if (c < '\u0020' || c > '\u007E') {
66-
// Delegate the trickier non-ASCII cases to the normal algorithm. Some of these
67-
// are escaped as \uXXXX, whilst others are represented literally. Since we're
68-
// using this primarily for header values that are generally (though not 100%
69-
// strictly?) ASCII-only, this should almost never happen.
70-
return JSON.stringify(c).slice(1, -1);
71-
} else {
72-
return c;
73-
}
74-
}).join('');
38+
return [...stringValue]
39+
.map(c => {
40+
if (c === '\b') {
41+
return `${escapeChar }b`;
42+
} else if (c === '\t') {
43+
return `${escapeChar }t`;
44+
} else if (c === '\n') {
45+
if (escapeNewlines) {
46+
return `${escapeChar }n`;
47+
}
48+
return c; // Don't just continue, or this is caught by < \u0020
49+
50+
} else if (c === '\f') {
51+
return `${escapeChar }f`;
52+
} else if (c === '\r') {
53+
if (escapeNewlines) {
54+
return `${escapeChar }r`;
55+
}
56+
return c; // Don't just continue, or this is caught by < \u0020
57+
58+
} else if (c === escapeChar) {
59+
return escapeChar + escapeChar;
60+
} else if (c === delimiter) {
61+
return escapeChar + delimiter;
62+
} else if (c < '\u0020' || c > '\u007E') {
63+
// Delegate the trickier non-ASCII cases to the normal algorithm. Some of these
64+
// are escaped as \uXXXX, whilst others are represented literally. Since we're
65+
// using this primarily for header values that are generally (though not 100%
66+
// strictly?) ASCII-only, this should almost never happen.
67+
return JSON.stringify(c).slice(1, -1);
68+
}
69+
return c;
70+
71+
})
72+
.join('');
7573
}
7674

7775
/**
@@ -81,8 +79,7 @@ export function escapeString(rawValue: any, options: EscapeOptions = {}) {
8179
*
8280
* If value is not a string, it will be stringified with .toString() first.
8381
*/
84-
export const escapeForSingleQuotes = (value: any) =>
85-
escapeString(value, { delimiter: "'" });
82+
export const escapeForSingleQuotes = (value: any) => escapeString(value, { delimiter: "'" });
8683

8784
/**
8885
* Make a string value safe to insert literally into a snippet within double quotes,
@@ -91,5 +88,4 @@ export const escapeForSingleQuotes = (value: any) =>
9188
*
9289
* If value is not a string, it will be stringified with .toString() first.
9390
*/
94-
export const escapeForDoubleQuotes = (value: any) =>
95-
escapeString(value, { delimiter: '"' });
91+
export const escapeForDoubleQuotes = (value: any) => escapeString(value, { delimiter: '"' });

src/targets/c/libcurl/client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export const libcurl: Client = {
2626
push('struct curl_slist *headers = NULL;');
2727

2828
headers.forEach(header => {
29-
push(`headers = curl_slist_append(headers, "${header}: ${escapeForDoubleQuotes(headersObj[header])}");`);
29+
push(
30+
`headers = curl_slist_append(headers, "${header}: ${escapeForDoubleQuotes(
31+
headersObj[header],
32+
)}");`,
33+
);
3034
});
3135

3236
push('curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);');

src/targets/ocaml/cohttp/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export const cohttp: Client = {
3939

4040
if (headers.length === 1) {
4141
push(
42-
`let headers = Header.add (Header.init ()) "${headers[0]}" "${escapeForDoubleQuotes(allHeaders[headers[0]])}" in`,
42+
`let headers = Header.add (Header.init ()) "${headers[0]}" "${escapeForDoubleQuotes(
43+
allHeaders[headers[0]],
44+
)}" in`,
4345
);
4446
} else if (headers.length > 1) {
4547
push('let headers = Header.add_list (Header.init ()) [');

src/targets/php/guzzle/client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,19 @@ export const guzzle: Client<GuzzleOptions> = {
123123
const headers = Object.keys(headersObj)
124124
.sort()
125125
.map(function (key) {
126-
return `${opts.indent}${opts.indent}'${key}' => '${escapeForSingleQuotes(headersObj[key])}',`;
126+
return `${
127+
opts.indent
128+
}${opts.indent}'${key}' => '${escapeForSingleQuotes(headersObj[key])}',`;
127129
});
128130

129131
// construct cookies
130132
const cookieString = cookies
131133
.map(cookie => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`)
132134
.join('; ');
133135
if (cookieString.length) {
134-
headers.push(`${opts.indent}${opts.indent}'cookie' => '${escapeForSingleQuotes(cookieString)}',`);
136+
headers.push(
137+
`${opts.indent}${opts.indent}'cookie' => '${escapeForSingleQuotes(cookieString)}',`,
138+
);
135139
}
136140

137141
if (headers.length) {

src/targets/php/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { escapeString } from "../../helpers/escape";
1+
import { escapeString } from '../../helpers/escape';
22

33
export const convertType = (obj: any[] | any, indent?: string, lastIndent?: string) => {
44
lastIndent = lastIndent || '';

src/targets/powershell/common.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
5656
}
5757

5858
if (postData.text) {
59-
commandOptions.push(`-ContentType '${
60-
escapeString(getHeader(allHeaders, 'content-type'), { delimiter: "'", escapeChar: '`' })
61-
}'`);
59+
commandOptions.push(
60+
`-ContentType '${escapeString(getHeader(allHeaders, 'content-type'), {
61+
delimiter: "'",
62+
escapeChar: '`',
63+
})}'`,
64+
);
6265
commandOptions.push(`-Body '${postData.text}'`);
6366
}
6467

0 commit comments

Comments
 (0)