-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The component name is not strict, resulting in the inability to run the VUE program #4422
Comments
I think there is a solution. Due to my limited technical ability, I don't know if this repair will cause other problems. Here I only provide my suggestions for your reference, thank you. The original function:
Rewritten as:
Let's take the following code as an example: The original function: Convert "a-b" to "a_b"
//Error: duplicate variable name Using the function I repaired, the following code will be generated:
Please note: "a-b" "a.b" are all html element names that conform to the w3c standard: A valid custom element name is a sequence of characters name that meets all of the following requirements: name must match the PotentialCustomElementName production: PotentialCustomElementName ::= name must not be any of the following: annotation-xml |
@qq974969638 I think we don't need using
PR #4429 |
Version
3.2.4
Reproduction link
https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8aDE+e3sgbXNnIH19PC9oMT5cbiAgIDx6ai3mtYvor5XkuIA+PC96ai3mtYvor5XkuIA+XG4gICA8emot5rWL6K+V5LqMPjwvemot5rWL6K+V5LqMPlxuPC90ZW1wbGF0ZT5cblxuPHNjcmlwdCBzZXR1cD5cbmNvbnN0IG1zZyA9ICdIZWxsbyBXb3JsZCEnXG48L3NjcmlwdD4ifQ==
Steps to reproduce
<!DOCTYPE html>
<body>
<div id="hello-vue" class="demo">
{{ message }}
<zj-测试一></zj-测试一>
<zj-测试二></zj-测试二>
</div>
</body>
<script src="https://unpkg.com/vue@next"></script>
<script>
const HelloVueApp = { data() { return { message: 'Hello Vue!!' } } };
Vue.createApp(HelloVueApp).mount('#hello-vue');
</script>
</html>
Uncaught SyntaxError: Identifier 'component_zj___' has already been declared
What is expected?
Vue should ignore invalid tags, and say "Hello Vue!!"
What is actually happening?
VUE cannot run
This is a demonstration with special characters that can be run:
https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8aDE+e3sgbXNnIH19PC9oMT5cbiAgIDx6ai3mtYvor5XkuIA+PC96ai3mtYvor5XkuIA+XG48L3RlbXBsYXRlPlxuXG48c2NyaXB0IHNldHVwPlxuY29uc3QgbXNnID0gJ0hlbGxvIFdvcmxkISdcbjwvc2NyaXB0PiJ9
Reason: I used a special html element tag name.
VUE uses the following code when converting element tag names.
#################
function toValidAssetId(name, type) {
return
${type}${name.replace(/[^\w]/g, '_')};
}
#################
Which resulted in:
The element tag "<zj-测试一>" is compiled into "component_zj___"
The element tag "<zj-测试二>" is compiled into "component_zj___"
Therefore, a variable name conflict occurred internally.
<!DOCTYPE html>
<body>
<div id="hello-vue" class="demo">
{{ message }}
<zj-测试一></zj-测试一>
</div>
</body>
<script src="https://unpkg.com/vue@next"></script>
<script>
const HelloVueApp = { data() { return { message: 'Hello Vue!!' } } };
Vue.createApp(HelloVueApp).mount('#hello-vue');
</script>
</html>
But there is a problem here. When VUE encounters an unknown tag that cannot be processed, should it be sent to the DOM for the browser to process, or should it be deleted?
How to explain, it can still run when only a special element name tag is reserved.
############## This is a special character code that can be run ####################
<!DOCTYPE html>
<body>
<div id="hello-vue" class="demo">
{{ message }}
<zj-测试一></zj-测试一>
</div>
</body>
<script src="https://unpkg.com/vue@next"></script>
<script>
const HelloVueApp = { data() { return { message: 'Hello Vue!!' } } };
Vue.createApp(HelloVueApp).mount('#hello-vue');
</script>
</html>
############## This is a special character code that can be run ####################
The text was updated successfully, but these errors were encountered: