Skip to content

Commit

Permalink
Merge pull request #721 from shufo/fix/timeout-on-unclosed-quote
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo authored Sep 24, 2022
2 parents 52e6fed + 6aa4e61 commit 30840c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions __tests__/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4573,4 +4573,23 @@ describe('formatter', () => {

await util.doubleFormatCheck(content, expected);
});

test('it should not timeout even if there is a quote in php expression', async () => {
const content = [
`@php`,
`// if breadcrumbs aren't defined in the CrudController, use the default breadcrumbs`,
`$breadcrumbs = $breadcrumbs ?? $defaultBreadcrumbs;`,
`@endphp`,
].join('\n');

const expected = [
`@php`,
`// if breadcrumbs aren't defined in the CrudController, use the default breadcrumbs`,
`$breadcrumbs = $breadcrumbs ?? $defaultBreadcrumbs;`,
`@endphp`,
``,
].join('\n');

await util.doubleFormatCheck(content, expected);
});
});
2 changes: 1 addition & 1 deletion src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ export default class Formatter {
}

preserveStringLiteralInPhp(content: any) {
return _.replace(content, /('(?:[^\\']+|\\.)*'|"(?:[^\\"]+|\\.)*")/g, (match: string) => {
return _.replace(content, /(\'([^\\']|\\.)*?\'|\"([^\\']|\\.)*?\")/gm, (match: string) => {
return `${this.storeStringLiteralInPhp(match)}`;
});
}
Expand Down

0 comments on commit 30840c3

Please sign in to comment.