@@ -157,11 +157,20 @@ namespace Playback {
157
157
return log ;
158
158
}
159
159
160
+ const canonicalizeForHarness = ts . createGetCanonicalFileName ( /*caseSensitive*/ false ) ; // This is done so tests work on windows _and_ linux
161
+ function sanitizeTestFilePath ( name : string ) {
162
+ const path = ts . toPath ( ts . normalizeSlashes ( name . replace ( / [ \^ < > : " | ? * % ] / g, "_" ) ) . replace ( / \. \. \/ / g, "__dotdot/" ) , "" , canonicalizeForHarness ) ;
163
+ if ( ts . startsWith ( path , "/" ) ) {
164
+ return path . substring ( 1 ) ;
165
+ }
166
+ return path ;
167
+ }
168
+
160
169
export function oldStyleLogIntoNewStyleLog ( log : IOLog , writeFile : typeof Harness . IO . writeFile , baseTestName : string ) {
161
170
if ( log . filesAppended ) {
162
171
for ( const file of log . filesAppended ) {
163
172
if ( file . contents !== undefined ) {
164
- file . contentsPath = ts . combinePaths ( "appended" , Harness . Compiler . sanitizeTestFilePath ( file . path ) ) ;
173
+ file . contentsPath = ts . combinePaths ( "appended" , sanitizeTestFilePath ( file . path ) ) ;
165
174
writeFile ( ts . combinePaths ( baseTestName , file . contentsPath ) , file . contents ) ;
166
175
delete file . contents ;
167
176
}
@@ -170,7 +179,7 @@ namespace Playback {
170
179
if ( log . filesWritten ) {
171
180
for ( const file of log . filesWritten ) {
172
181
if ( file . contents !== undefined ) {
173
- file . contentsPath = ts . combinePaths ( "written" , Harness . Compiler . sanitizeTestFilePath ( file . path ) ) ;
182
+ file . contentsPath = ts . combinePaths ( "written" , sanitizeTestFilePath ( file . path ) ) ;
174
183
writeFile ( ts . combinePaths ( baseTestName , file . contentsPath ) , file . contents ) ;
175
184
delete file . contents ;
176
185
}
@@ -180,7 +189,7 @@ namespace Playback {
180
189
for ( const file of log . filesRead ) {
181
190
const { contents } = file . result ;
182
191
if ( contents !== undefined ) {
183
- file . result . contentsPath = ts . combinePaths ( "read" , Harness . Compiler . sanitizeTestFilePath ( file . path ) ) ;
192
+ file . result . contentsPath = ts . combinePaths ( "read" , sanitizeTestFilePath ( file . path ) ) ;
184
193
writeFile ( ts . combinePaths ( baseTestName , file . result . contentsPath ) , contents ) ;
185
194
const len = contents . length ;
186
195
if ( len >= 2 && contents . charCodeAt ( 0 ) === 0xfeff ) {
@@ -235,8 +244,8 @@ namespace Playback {
235
244
if ( recordLog !== undefined ) {
236
245
let i = 0 ;
237
246
const fn = ( ) => recordLogFileNameBase + i ;
238
- while ( underlying . fileExists ( fn ( ) + " .json") ) i ++ ;
239
- underlying . writeFile ( ts . combinePaths ( fn ( ) , "test.json" ) , JSON . stringify ( oldStyleLogIntoNewStyleLog ( recordLog , ( path , string ) => underlying . writeFile ( ts . combinePaths ( fn ( ) , path ) , string ) , fn ( ) ) , null , 4 ) ) ; // tslint:disable-line:no-null-keyword
247
+ while ( underlying . fileExists ( ts . combinePaths ( fn ( ) , "test .json") ) ) i ++ ;
248
+ underlying . writeFile ( ts . combinePaths ( fn ( ) , "test.json" ) , JSON . stringify ( oldStyleLogIntoNewStyleLog ( recordLog , ( path , string ) => underlying . writeFile ( path , string ) , fn ( ) ) , null , 4 ) ) ; // tslint:disable-line:no-null-keyword
240
249
recordLog = undefined ;
241
250
}
242
251
} ;
@@ -415,4 +424,4 @@ namespace Playback {
415
424
initWrapper ( wrapper , underlying ) ;
416
425
return wrapper ;
417
426
}
418
- }
427
+ }
0 commit comments