We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
你好,这个我们在使用中发现一个bug,对于空格有一种情况没有处理,如下面这种情况:
<img src = "../images/icon_404.png" />
我们这边修改了一下,更改代码如下
function replaceSrc(fileContent, exclude) { fileContent = fileContent.replace(/((\<img[^\<\>]*? src)|(\<link[^\<\>]*? href))[\s]*=[\s]*\\?[\"\']?[^\'\"\<\>\+]+?\\?[\'\"][^\<\>]*?[/]?\>/ig, function(str){ console.log(''); console.log(str); var reg = /\s+((src)|(href))[\s]*=[\s]*\\?[\'\"][^\"\']+\\?[\'\"]/i; var regResult = reg.exec(str); if(!regResult) return str; var attrName = /\w+\s*=\s*/.exec(regResult[0])[0].replace(/\s*=\s*$/, ''); var imgUrl = regResult[0].replace(/\w+\s*=\s*/, '').replace(/[\\\'\"]/g, ''); if(!imgUrl) return str; // 避免空src引起编译失败 if(/^(http(s?):)?\/\//.test(imgUrl)) return str; // 绝对路径的图片不处理 if(!/\.(jpg|jpeg|png|gif|svg|webp)/i.test(imgUrl)) return str; // 非静态图片不处理 if(exclude && imgUrl.indexOf(exclude) != -1) return str; // 不处理被排除的 imgUrl = imgUrl.replace(/^\s*/g, ''); // 去掉左边空格 if(!(/^[\.\/]/).test(imgUrl)) { imgUrl = './' + imgUrl; } var res = str.replace(reg, " "+attrName+"=\"+JSON.stringify(require("+JSON.stringify(imgUrl)+"))+\""); console.log(res); return res; }); return fileContent; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
你好,这个我们在使用中发现一个bug,对于空格有一种情况没有处理,如下面这种情况:
我们这边修改了一下,更改代码如下
The text was updated successfully, but these errors were encountered: