@@ -16,6 +16,7 @@ function fromBase64(str) {
1616class PreviousMap {
1717 constructor ( css , opts ) {
1818 if ( opts . map === false ) return
19+ if ( opts . unsafeMap ) this . unsafeMap = true
1920 this . loadAnnotation ( css )
2021 this . inline = this . startWith ( this . annotation , 'data:' )
2122
@@ -30,7 +31,7 @@ class PreviousMap {
3031
3132 consumer ( ) {
3233 if ( ! this . consumerCache ) {
33- this . consumerCache = new SourceMapConsumer ( this . json ?? this . text )
34+ this . consumerCache = new SourceMapConsumer ( this . json || this . text )
3435 }
3536 return this . consumerCache
3637 }
@@ -83,7 +84,12 @@ class PreviousMap {
8384 }
8485 }
8586
86- loadFile ( path ) {
87+ loadFile ( path , cssFile , trusted ) {
88+ if ( ! trusted && ! this . unsafeMap ) {
89+ if ( ! / \. m a p $ / i. test ( path ) ) {
90+ return undefined
91+ }
92+ }
8793 this . root = dirname ( path )
8894 if ( existsSync ( path ) ) {
8995 this . mapFile = path
@@ -100,7 +106,7 @@ class PreviousMap {
100106 } else if ( typeof prev === 'function' ) {
101107 let prevPath = prev ( file )
102108 if ( prevPath ) {
103- let map = this . loadFile ( prevPath )
109+ let map = this . loadFile ( prevPath , file , true )
104110 if ( ! map ) {
105111 throw new Error (
106112 'Unable to load previous source map: ' + prevPath . toString ( )
@@ -124,11 +130,11 @@ class PreviousMap {
124130 } else if ( this . annotation ) {
125131 let map = this . annotation
126132 if ( file ) map = join ( dirname ( file ) , map )
127- let unknown = this . loadFile ( map )
133+ let unknown = this . loadFile ( map , file , false )
128134 if ( unknown ) {
129135 try {
130136 this . json = JSON . parse ( unknown . replace ( / ^ \) ] } ' [ ^ \n ] * \n / , '' ) )
131- } catch ( e ) {
137+ } catch {
132138 return undefined
133139 }
134140 }
0 commit comments