Skip to content

fix:image.alt #79

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions packages/hap-compiler/src/template/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1864,12 +1864,7 @@ function checkAttr(name, value, output, tagName, locationInfo, options) {
* @returns {boolean}
*/
function shouldConvertPath(name, value, tagName) {
const skip = name === 'alt' && value === 'blank'
if (skip) {
return false
}

if (['src', 'alt'].includes(name) && value && ['img', 'video'].indexOf(tagName) > -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果开发者alt属性写的本地图片路径,打包不进行路径处理,运行时会无法解析

if (['src'].includes(name) && value && ['img', 'video'].indexOf(tagName) > -1) {
if (!/^(data:|http|{{)/.test(value)) {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2250,15 +2250,15 @@ exports[`Component 编译测试 ux components: ../../../lib/loaders/template-loa
\\"attr\\": {
\\"dataData2\\": function () {return this.attrData},
\\"src\\": \\"/packages/hap-dsl-xvm/test/case/ux/TestComponent/Image/Common/home.png\\",
\\"alt\\": \\"/packages/hap-dsl-xvm/test/case/ux/TestComponent/Image/Common/home.png\\"
\\"alt\\": \\"./Common/home.png\\"
}
},
{
\\"type\\": \\"image\\",
\\"attr\\": {
\\"dataData1Data2\\": \\"abc\\",
\\"src\\": \\"/packages/hap-dsl-xvm/test/case/ux/TestComponent/Common/home.png\\",
\\"alt\\": \\"/packages/hap-dsl-xvm/test/case/ux/TestComponent/Common/home.png\\"
\\"alt\\": \\"../Common/home.png\\"
}
},
{
Expand Down
Binary file not shown.
Loading