Skip to content

Commit

Permalink
(fix) refine attributeRegex
Browse files Browse the repository at this point in the history
Fix attributeRegex that correctly match attributes that are not enclosed in quotes.
fix sveltejs#344
  • Loading branch information
Rolaka committed Feb 5, 2023
1 parent 3a353ab commit 8f1cce8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/extractAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AttributeNode, TextNode } from '../print/nodes';

export function extractAttributes(html: string): AttributeNode[] {
const extractAttributesRegex = /<[a-z]+[\s\n]*([\s\S]*?)>/im;
const attributeRegex = /([^\s=]+)(?:=("|')([\s\S]*?)\2)?/gim;
const attributeRegex = /([^\s=]+)(?:=("|')([\s\S]*?)\2)?(?:[ >]|$)/gim;

const [, attributesString] = html.match(extractAttributesRegex)!;

Expand Down

0 comments on commit 8f1cce8

Please sign in to comment.