Skip to content

Commit

Permalink
bug xif
Browse files Browse the repository at this point in the history
  • Loading branch information
navyxie committed Jul 28, 2016
1 parent 2642e76 commit 4c6e723
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ gulp.task('originTemplateContent',['returnToOrigin']);

## change log

- 0.2.2

```
bug fix:
when template contain script, and have code xxx.src=xxx, will cause bug.
```

- 0.2.0

```
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function syncFileToBuffer (filepath) {

var extList = ['.BMP', '.JPG', '.JPEG', '.PNG', '.GIF'];

function isInExtList (ext) {
return (_.indexOf(extList, ext) !== -1);
}
/**
* filePath current filepath
* url staticfile(image) url
Expand Down Expand Up @@ -72,7 +75,7 @@ function formatUrl (filePath, url, options) {
}

// skip when static file not in extList
if (_.indexOf(extList, path.extname(formattedUrl).toUpperCase()) === -1) {
if (!isInExtList(path.extname(formattedUrl).toUpperCase())) {
return formattedUrl;
}

Expand Down Expand Up @@ -142,7 +145,7 @@ function customContent (fileContents, filePath, options) {
var srcReg = /(src=)['"]?([^'"]*)['"]?/i;
fileContents = fileContents.replace(imgReg, function (srcStr) {
return srcStr.replace(srcReg, function (originStr, srcEqualStr, imageUrl) {
if (srcEqualStr && imageUrl) {
if (srcEqualStr && imageUrl && isInExtList(path.extname(imageUrl).toUpperCase())) {
return srcEqualStr + "'" + formatUrl(filePath, imageUrl, options) + "'";
} else {
return srcStr;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-custom-css-urls",
"version": "0.2.1",
"version": "0.2.2",
"description": "a gulp plugin custom image url inline in css",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ describe('gulp-custom-css-urls', function() {
it('html -> forceModify() should be ok if image url is relative to website root path', function () {
vfs.src('test/views/forcemodify.html')
.pipe(customCssUrls({
forceModify: function (imageUrl, filePath) {
forceModify: function (imagesUrl, filePath) {
var qiniu_host = 'https://demo.com';
var ext = path.extname(imagesUrl);
if (!ext) {
return imagesUrl;
}
return imagesUrl.replace(ext, '').replace(qiniu_host, '').replace(/_\d{1,}_\d{1,}\.\d{1,}$/, '') + ext;
if (!ext) {
return imagesUrl;
}
return imagesUrl.replace(ext, '').replace(qiniu_host, '').replace(/_\d{1,}_\d{1,}\.\d{1,}$/, '') + ext;
},
ext: 'html'
}))
Expand Down
5 changes: 5 additions & 0 deletions test/views/forcemodify.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
<div id="header"><img src="https://demo.com/images/example.png" /></div>
<div id="footer"><img src="/images/example.png" /></div>
</body>
<script type="text/javascript">
var a = "test.png";
var q = {};
q.src=a;
</script>
</html>

0 comments on commit 4c6e723

Please sign in to comment.