44const
55 assert = require ( 'assert' ) ,
66 os = require ( 'os' ) ,
7+ path = require ( 'path' ) ,
78 inbandStandardTests = require ( './name-inband-standard' ) ,
89 tmp = require ( '../lib/tmp' ) ;
910
@@ -63,15 +64,15 @@ describe('tmp', function () {
6364 } ) ;
6465 } ) ;
6566 } ) ;
66- describe ( 'on issue #246 ' , function ( ) {
67+ describe ( 'on issue #268 ' , function ( ) {
6768 const origfn = os . tmpdir ;
68- it ( 'must produce correct name on os.tmpdir() returning path that includes double quotes' , function ( done ) {
69+ it ( `should not alter ${ isWindows ? 'invalid' : 'valid' } path on os.tmpdir() returning path that includes double quotes` , function ( done ) {
6970 const tmpdir = isWindows ? '"C:\\Temp With Spaces"' : '"/tmp with spaces"' ;
7071 os . tmpdir = function ( ) { return tmpdir ; } ;
7172 tmp . tmpName ( function ( err , name ) {
73+ const index = name . indexOf ( path . sep + tmpdir + path . sep ) ;
7274 try {
73- assert . ok ( name . indexOf ( '"' ) === - 1 ) ;
74- assert . ok ( name . startsWith ( tmpdir . replace ( / [ " ' ] / g, '' ) ) ) ;
75+ assert . ok ( index > 0 , `${ tmpdir } should have been a subdirectory name in ${ name } ` ) ;
7576 } catch ( err ) {
7677 return done ( err ) ;
7778 } finally {
@@ -80,13 +81,13 @@ describe('tmp', function () {
8081 done ( ) ;
8182 } ) ;
8283 } ) ;
83- it ( 'must produce correct name on os.tmpdir() returning path that includes single quotes' , function ( done ) {
84+ it ( 'should not alter valid path on os.tmpdir() returning path that includes single quotes' , function ( done ) {
8485 const tmpdir = isWindows ? '\'C:\\Temp With Spaces\'' : '\'/tmp with spaces\'' ;
8586 os . tmpdir = function ( ) { return tmpdir ; } ;
8687 tmp . tmpName ( function ( err , name ) {
88+ const index = name . indexOf ( path . sep + tmpdir + path . sep ) ;
8789 try {
88- assert . ok ( name . indexOf ( '\'' ) === - 1 ) ;
89- assert . ok ( name . startsWith ( tmpdir . replace ( / [ " ' ] / g, '' ) ) ) ;
90+ assert . ok ( index > 0 , `${ tmpdir } should have been a subdirectory name in ${ name } ` ) ;
9091 } catch ( err ) {
9192 return done ( err ) ;
9293 } finally {
0 commit comments