File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
packages/vite/src/node/plugins Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ export function getScriptInfo(node: DefaultTreeAdapterMap['element']): {
191
191
return { src, sourceCodeLocation, isModule, isAsync }
192
192
}
193
193
194
- const attrValueWithQuotesStartRE = / = [ \s \t \n \r ] * " /
194
+ const attrValueStartRE = / = [ \s \t \n \r ] * ( [ " ' ] | . ) /
195
195
196
196
export function overwriteAttrValue (
197
197
s : MagicString ,
@@ -202,12 +202,18 @@ export function overwriteAttrValue(
202
202
sourceCodeLocation ! . startOffset ,
203
203
sourceCodeLocation ! . endOffset
204
204
)
205
- const valueWithQuotes = srcString . match ( attrValueWithQuotesStartRE )
206
- const valueOffset =
207
- 1 + ( valueWithQuotes ? srcString . indexOf ( '"' ) : srcString . indexOf ( '=' ) )
205
+ const valueStart = srcString . match ( attrValueStartRE )
206
+ if ( ! valueStart ) {
207
+ // overwrite attr value can only be called for a well-defined value
208
+ throw new Error (
209
+ `[vite:html] internal error, failed to overwrite attribute value`
210
+ )
211
+ }
212
+ const wrapOffset = valueStart [ 1 ] ? 1 : 0
213
+ const valueOffset = valueStart . index ! + valueStart [ 0 ] . length - 1
208
214
s . overwrite (
209
- sourceCodeLocation . startOffset + valueOffset ,
210
- sourceCodeLocation . endOffset + ( valueWithQuotes ? - 1 : 0 ) ,
215
+ sourceCodeLocation . startOffset + valueOffset + wrapOffset ,
216
+ sourceCodeLocation . endOffset - wrapOffset ,
211
217
newValue ,
212
218
{ contentOnly : true }
213
219
)
You can’t perform that action at this time.
0 commit comments