File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ function loadCss (context, resource) {
1515
1616 return context . loadResource ( cssResource ) . then ( function handleLoadedSource ( loadedResource ) {
1717 var relativePath = utils . getRelativePath ( filename , loadedResource . getFilename ( ) ) ;
18- text = text . replace ( cssUrl , relativePath ) ;
18+ text = text . replace ( new RegExp ( cssUrl , 'g' ) , relativePath ) ;
1919 return Promise . resolve ( ) ;
2020 } ) ;
2121 } ) ;
Original file line number Diff line number Diff line change @@ -112,5 +112,28 @@ describe('Css handler', function () {
112112 done ( ) ;
113113 } ) . catch ( done ) ;
114114 } ) ;
115+
116+ it ( 'should replace all occurencies of the same sources in text with local files' , function ( done ) {
117+ sinon . stub ( scraper , 'loadResource' ) . returns ( Promise . resolve ( new Resource ( 'http://example.com/img.jpg' , 'local/img.jpg' ) ) ) ;
118+
119+ var css = '\
120+ .a {background: url("http://example.com/img.jpg")} \
121+ .b {background: url("http://example.com/img.jpg")}\
122+ .c {background: url("http://example.com/img.jpg")}\
123+ ' ;
124+
125+ var po = new Resource ( 'http://example.com' , '1.css' ) ;
126+ po . setText ( css ) ;
127+
128+ return loadCss ( scraper , po ) . then ( function ( ) {
129+ var text = po . getText ( ) ;
130+ var numberOfLocalResourceMatches = text . match ( / l o c a l \/ i m g .j p g / g) . length ;
131+
132+ text . should . not . containEql ( 'http://example.com/img.jpg' ) ;
133+ text . should . containEql ( 'local/img.jpg' ) ;
134+ numberOfLocalResourceMatches . should . be . eql ( 3 ) ;
135+ done ( ) ;
136+ } ) . catch ( done ) ;
137+ } ) ;
115138 } ) ;
116139} ) ;
You can’t perform that action at this time.
0 commit comments