Skip to content

Commit

Permalink
Merge pull request #310 from icedream/pr/fix-backticks-and-single-quo…
Browse files Browse the repository at this point in the history
…tes-bad-escape
  • Loading branch information
mrlubos authored Apr 9, 2024
2 parents 399a0ca + a8e9e33 commit 2d2a97f
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/two-elephants-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix: ensure strings with both single/double quotes and backticks are escaped properly ([#310](https://github.com/hey-api/openapi-ts/pull/310))
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/compiler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ots = {
!value.startsWith('`') &&
!value.endsWith('`')
) {
value = `\`${value}\``;
value = `\`${value.replace(/`/g, '\\`')}\``;
}
const text = encodeURIComponent(value);
if (value.startsWith('`')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type CommentWithBreaks = number;
*/
export type CommentWithBackticks = number;

/**
* Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work
*/
export type CommentWithBackticksAndQuotes = number;

/**
* Testing slashes in string: \backwards\\\ and /forwards/// should work
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const $CommentWithBackticks = {
type: 'integer',
} as const;

export const $CommentWithBackticksAndQuotes = {
description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`,
type: 'integer',
} as const;

export const $CommentWithSlashes = {
description: 'Testing slashes in string: \backwards\\ and /forwards/// should work',
type: 'integer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type CommentWithBreaks = number;
*/
export type CommentWithBackticks = number;

/**
* Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work
*/
export type CommentWithBackticksAndQuotes = number;

/**
* Testing slashes in string: \backwards\\\ and /forwards/// should work
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const $CommentWithBackticks = {
type: 'integer',
} as const;

export const $CommentWithBackticksAndQuotes = {
description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`,
type: 'integer',
} as const;

export const $CommentWithSlashes = {
description: 'Testing slashes in string: \backwards\\ and /forwards/// should work',
type: 'integer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type CommentWithBreaks = number;
*/
export type CommentWithBackticks = number;

/**
* Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work
*/
export type CommentWithBackticksAndQuotes = number;

/**
* Testing slashes in string: \backwards\\\ and /forwards/// should work
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const $CommentWithBackticks = {
type: 'integer',
} as const;

export const $CommentWithBackticksAndQuotes = {
description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`,
type: 'integer',
} as const;

export const $CommentWithSlashes = {
description: 'Testing slashes in string: \backwards\\ and /forwards/// should work',
type: 'integer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type CommentWithBreaks = number;
*/
export type CommentWithBackticks = number;

/**
* Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work
*/
export type CommentWithBackticksAndQuotes = number;

/**
* Testing slashes in string: \backwards\\\ and /forwards/// should work
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const $CommentWithBackticks = {
type: 'integer',
} as const;

export const $CommentWithBackticksAndQuotes = {
description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`,
type: 'integer',
} as const;

export const $CommentWithSlashes = {
description: 'Testing slashes in string: \backwards\\ and /forwards/// should work',
type: 'integer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type CommentWithBreaks = number;
*/
export type CommentWithBackticks = number;

/**
* Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work
*/
export type CommentWithBackticksAndQuotes = number;

/**
* Testing slashes in string: \backwards\\\ and /forwards/// should work
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const $CommentWithBackticks = {
type: 'integer',
} as const;

export const $CommentWithBackticksAndQuotes = {
description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`,
type: 'integer',
} as const;

export const $CommentWithSlashes = {
description: 'Testing slashes in string: \backwards\\ and /forwards/// should work',
type: 'integer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type CommentWithBreaks = number;
*/
export type CommentWithBackticks = number;

/**
* Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work
*/
export type CommentWithBackticksAndQuotes = number;

/**
* Testing slashes in string: \backwards\\\ and /forwards/// should work
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const $CommentWithBackticks = {
type: 'integer',
} as const;

export const $CommentWithBackticksAndQuotes = {
description: `Testing backticks and quotes in string: \`backticks\`, 'quotes', "double quotes" and \`\`\`multiple backticks\`\`\` should work`,
type: 'integer',
} as const;

export const $CommentWithSlashes = {
description: 'Testing slashes in string: \backwards\\ and /forwards/// should work',
type: 'integer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type CommentWithBreaks = number;
*/
export type CommentWithBackticks = number;

/**
* Testing backticks and quotes in string: `backticks`, 'quotes', "double quotes" and ```multiple backticks``` should work
*/
export type CommentWithBackticksAndQuotes = number;

/**
* Testing slashes in string: \backwards\\\ and /forwards/// should work
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/openapi-ts/test/spec/v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,10 @@
"description": "Testing backticks in string: `backticks` and ```multiple backticks``` should work",
"type": "integer"
},
"CommentWithBackticksAndQuotes": {
"description": "Testing backticks and quotes in string: `backticks`, 'quotes', \"double quotes\" and ```multiple backticks``` should work",
"type": "integer"
},
"CommentWithSlashes": {
"description": "Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work",
"type": "integer"
Expand Down
4 changes: 4 additions & 0 deletions packages/openapi-ts/test/spec/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,10 @@
"description": "Testing backticks in string: `backticks` and ```multiple backticks``` should work",
"type": "integer"
},
"CommentWithBackticksAndQuotes": {
"description": "Testing backticks and quotes in string: `backticks`, 'quotes', \"double quotes\" and ```multiple backticks``` should work",
"type": "integer"
},
"CommentWithSlashes": {
"description": "Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work",
"type": "integer"
Expand Down

0 comments on commit 2d2a97f

Please sign in to comment.