Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commitcfd73c2

Browse files
committed
fix: handle encoded tabs and newlines in attributes for Chrome a[href] and IE/Edge
fixvuejs#6828,fixvuejs#6916
1 parent83ed926 commitcfd73c2

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

‎flow/compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ declare type CompilerOptions = {
1414
preserveWhitespace?:boolean;
1515
isFromDOM?:boolean;
1616
shouldDecodeTags?:boolean;
17-
shouldDecodeNewlines?:boolean;
17+
shouldDecodeNewlines?:boolean;
18+
shouldDecodeNewlinesForHref?:boolean;
1819

1920
// for ssr optimization compiler
2021
scopeId?:string;

‎src/compiler/parser/html-parser.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ const decodingMap = {
3939
'>':'>',
4040
'"':'"',
4141
'&':'&',
42-
'
':'\n'
42+
'
':'\n',
43+
'	':'\t'
4344
}
4445
constencodedAttr=/&(?:lt|gt|quot|amp);/g
45-
constencodedAttrWithNewLines=/&(?:lt|gt|quot|amp|#10);/g
46+
constencodedAttrWithNewLines=/&(?:lt|gt|quot|amp|#10|#9);/g
4647

4748
// #5992
4849
constisIgnoreNewlineTag=makeMap('pre,textarea',true)
@@ -233,12 +234,12 @@ export function parseHTML (html, options) {
233234
if(args[5]===''){deleteargs[5]}
234235
}
235236
constvalue=args[3]||args[4]||args[5]||''
237+
constshouldDecodeNewlines=tagName==='a'&&args[1]==='href'
238+
?options.shouldDecodeNewlinesForHref
239+
:options.shouldDecodeNewlines
236240
attrs[i]={
237241
name:args[1],
238-
value:decodeAttr(
239-
value,
240-
options.shouldDecodeNewlines
241-
)
242+
value:decodeAttr(value,shouldDecodeNewlines)
242243
}
243244
}
244245

‎src/compiler/parser/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export function parse (
107107
isUnaryTag:options.isUnaryTag,
108108
canBeLeftOpenTag:options.canBeLeftOpenTag,
109109
shouldDecodeNewlines:options.shouldDecodeNewlines,
110+
shouldDecodeNewlinesForHref:options.shouldDecodeNewlinesForHref,
110111
shouldKeepComment:options.comments,
111112
start(tag,attrs,unary){
112113
// check namespace.

‎src/platforms/web/entry-runtime-with-compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { mark, measure } from 'core/util/perf'
66

77
importVuefrom'./runtime/index'
88
import{query}from'./util/index'
9-
import{shouldDecodeNewlines}from'./util/compat'
109
import{compileToFunctions}from'./compiler/index'
10+
import{shouldDecodeNewlines,shouldDecodeNewlinesForHref}from'./util/compat'
1111

1212
constidToTemplate=cached(id=>{
1313
constel=query(id)
@@ -64,6 +64,7 @@ Vue.prototype.$mount = function (
6464

6565
const{render,staticRenderFns}=compileToFunctions(template,{
6666
shouldDecodeNewlines,
67+
shouldDecodeNewlinesForHref,
6768
delimiters:options.delimiters,
6869
comments:options.comments
6970
},this)

‎src/platforms/web/util/compat.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import{inBrowser}from'core/util/index'
44

55
// check whether current browser encodes a char inside attribute values
6-
functionshouldDecode(content:string,encoded:string):boolean{
7-
constdiv=document.createElement('div')
8-
div.innerHTML=`<div a="${content}"/>`
9-
returndiv.innerHTML.indexOf(encoded)>0
6+
letdiv
7+
functiongetShouldDecode(href:boolean):boolean{
8+
div=div||document.createElement('div')
9+
div.innerHTML=href ?`<a href="\n"/>` :`<div a="\n"/>`
10+
returndiv.innerHTML.indexOf('&#10;')>0
1011
}
1112

12-
// #3663
13-
// IE encodes newlines inside attribute values while other browsers don't
14-
exportconstshouldDecodeNewlines=inBrowser ?shouldDecode('\n','&#10;') :false
13+
// #3663: IE encodes newlines inside attribute values while other browsers don't
14+
exportconstshouldDecodeNewlines=inBrowser ?getShouldDecode(false) :false
15+
// #6828: chrome encodes content in a[href]
16+
exportconstshouldDecodeNewlinesForHref=inBrowser ?getShouldDecode(true) :false

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp