From 8be1957e15449dbd6a9bfef21535b2788432908b Mon Sep 17 00:00:00 2001 From: Shuhei Hayashibara Date: Tue, 17 Oct 2023 03:42:59 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20unexpected=20result=20whe?= =?UTF-8?q?n=20attrs=20are=20not=20separated=20by=20space?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When html tag attributes are not separated by space like class=""foo="", formatter will output unexpected result ✅ Closes: #878 --- .../snapshots/no_space_quotation.snapshot | 29 +++++++++++++++++++ src/formatter.ts | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 __tests__/fixtures/snapshots/no_space_quotation.snapshot diff --git a/__tests__/fixtures/snapshots/no_space_quotation.snapshot b/__tests__/fixtures/snapshots/no_space_quotation.snapshot new file mode 100644 index 00000000..5885d684 --- /dev/null +++ b/__tests__/fixtures/snapshots/no_space_quotation.snapshot @@ -0,0 +1,29 @@ +------------------------------------options---------------------------------------- +{} +------------------------------------content---------------------------------------- + + + +------------------------------------expected---------------------------------------- + + + diff --git a/src/formatter.ts b/src/formatter.ts index ed7b3baf..8438dcee 100644 --- a/src/formatter.ts +++ b/src/formatter.ts @@ -881,7 +881,7 @@ export default class Formatter { async preserveHtmlAttributes(content: any) { return _.replace( content, - /(?<=<[\w\-\.\:\_]+[^]*\s)(?!x-bind)([^\s\:][^\s]+\s*=\s*(["'])(?)/gms, + /(?<=<[\w\-\.\:\_]+[^]*\s)(?!x-bind)([^\s\:][^\s\'\"]+\s*=\s*(["'])(?)/gms, (match: string) => `${this.storeHtmlAttribute(match)}`, ); }