@@ -9,35 +9,39 @@ const testStrings = [
99 'Simple string' ,
1010 'String with spaces' ,
1111 'String with "double quotes"' ,
12- ' String with \ 'single quotes\'' ,
12+ " String with 'single quotes'" ,
1313 'String with $variable' ,
1414 'String with `backticks`' ,
1515 'String with newline\ncharacter' ,
1616 'String with & and | operators' ,
1717 'String with > redirect' ,
1818 'String with * wildcard' ,
19- 'Complex string with "quotes", \'single\', $var, `backticks`, \n, and special chars &|><*'
19+ 'Complex string with "quotes", \'single\', $var, `backticks`, \n, and special chars &|><*' ,
2020] ;
2121
2222console . log ( '=== Testing stdinContent approaches ===' ) ;
2323
2424// Helper function to wait for all tests to complete
25- const wait = ( ms ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
25+ const wait = ( ms ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
2626
2727// Helper function to execute a command with encoded content
28- const execWithEncodedContent = async ( command , content , isWindows = process . platform === 'win32' ) => {
28+ const execWithEncodedContent = async (
29+ command ,
30+ content ,
31+ isWindows = process . platform === 'win32' ,
32+ ) => {
2933 return new Promise ( ( resolve , reject ) => {
3034 const encodedContent = Buffer . from ( content ) . toString ( 'base64' ) ;
3135 let cmd ;
32-
36+
3337 if ( isWindows ) {
3438 // Windows approach using PowerShell
3539 cmd = `powershell -Command "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${ encodedContent } ')) | ${ command } "` ;
3640 } else {
3741 // POSIX approach (Linux/macOS)
3842 cmd = `echo "${ encodedContent } " | base64 -d | ${ command } ` ;
3943 }
40-
44+
4145 exec ( cmd , ( error , stdout , stderr ) => {
4246 if ( error ) {
4347 reject ( error ) ;
@@ -52,7 +56,7 @@ const execWithEncodedContent = async (command, content, isWindows = process.plat
5256console . log ( '\n=== Testing Base64 encoding approach ===' ) ;
5357for ( const str of testStrings ) {
5458 console . log ( `\nOriginal: "${ str } "` ) ;
55-
59+
5660 try {
5761 // Test the encoded content approach
5862 const { stdout } = await execWithEncodedContent ( 'cat' , str ) ;
@@ -61,7 +65,7 @@ for (const str of testStrings) {
6165 } catch ( error ) {
6266 console . error ( `Error: ${ error . message } ` ) ;
6367 }
64-
68+
6569 // Add a small delay to ensure orderly output
6670 await wait ( 100 ) ;
6771}
@@ -70,30 +74,33 @@ for (const str of testStrings) {
7074console . log ( '\n=== Comparing with temporary file approach ===' ) ;
7175for ( const str of testStrings ) {
7276 console . log ( `\nOriginal: "${ str } "` ) ;
73-
77+
7478 // Create a temporary file with the content
7579 const tempFile = path . join ( os . tmpdir ( ) , `test-content-${ Date . now ( ) } .txt` ) ;
7680 fs . writeFileSync ( tempFile , str ) ;
77-
81+
7882 // Execute command using the temporary file
7983 exec ( `cat "${ tempFile } "` , async ( error , stdout , stderr ) => {
8084 console . log ( `Output (temp file): "${ stdout . trim ( ) } "` ) ;
8185 console . log ( `Success (temp file): ${ stdout . trim ( ) === str } ` ) ;
82-
86+
8387 try {
8488 // Test the encoded content approach
85- const { stdout : encodedStdout } = await execWithEncodedContent ( 'cat' , str ) ;
89+ const { stdout : encodedStdout } = await execWithEncodedContent (
90+ 'cat' ,
91+ str ,
92+ ) ;
8693 console . log ( `Output (encoded): "${ encodedStdout . trim ( ) } "` ) ;
8794 console . log ( `Success (encoded): ${ encodedStdout . trim ( ) === str } ` ) ;
8895 console . log ( `Match: ${ stdout . trim ( ) === encodedStdout . trim ( ) } ` ) ;
8996 } catch ( error ) {
9097 console . error ( `Error: ${ error . message } ` ) ;
9198 }
92-
99+
93100 // Clean up the temporary file
94101 fs . unlinkSync ( tempFile ) ;
95102 } ) ;
96-
103+
97104 // Add a small delay to ensure orderly output
98105 await wait ( 300 ) ;
99- }
106+ }
0 commit comments