@@ -55,6 +55,34 @@ export const plugin: PluginDefinition = {
5555 } ,
5656} ;
5757
58+ /**
59+ * Decodes escape sequences in shell $'...' strings
60+ * Handles Unicode escape sequences (\uXXXX) and common escape codes
61+ */
62+ function decodeShellString ( str : string ) : string {
63+ return str
64+ . replace ( / \\ u ( [ 0 - 9 a - f A - F ] { 4 } ) / g, ( _ , hex ) => String . fromCharCode ( parseInt ( hex , 16 ) ) )
65+ . replace ( / \\ x ( [ 0 - 9 a - f A - F ] { 2 } ) / g, ( _ , hex ) => String . fromCharCode ( parseInt ( hex , 16 ) ) )
66+ . replace ( / \\ n / g, '\n' )
67+ . replace ( / \\ r / g, '\r' )
68+ . replace ( / \\ t / g, '\t' )
69+ . replace ( / \\ ' / g, "'" )
70+ . replace ( / \\ " / g, '"' )
71+ . replace ( / \\ \\ / g, '\\' ) ;
72+ }
73+
74+ /**
75+ * Checks if a string might contain escape sequences that need decoding
76+ * If so, decodes them; otherwise returns the string as-is
77+ */
78+ function maybeDecodeEscapeSequences ( str : string ) : string {
79+ // Check if the string contains escape sequences that shell-quote might not handle
80+ if ( str . includes ( '\\u' ) || str . includes ( '\\x' ) ) {
81+ return decodeShellString ( str ) ;
82+ }
83+ return str ;
84+ }
85+
5886export function convertCurl ( rawData : string ) {
5987 if ( ! rawData . match ( / ^ \s * c u r l / ) ) {
6088 return null ;
@@ -86,9 +114,11 @@ export function convertCurl(rawData: string) {
86114 for ( const parseEntry of normalizedParseEntries ) {
87115 if ( typeof parseEntry === 'string' ) {
88116 if ( parseEntry . startsWith ( '$' ) ) {
89- currentCommand . push ( parseEntry . slice ( 1 ) ) ;
117+ // Handle $'...' strings from shell-quote - decode escape sequences
118+ currentCommand . push ( decodeShellString ( parseEntry . slice ( 1 ) ) ) ;
90119 } else {
91- currentCommand . push ( parseEntry ) ;
120+ // Decode escape sequences that shell-quote might not handle
121+ currentCommand . push ( maybeDecodeEscapeSequences ( parseEntry ) ) ;
92122 }
93123 continue ;
94124 }
@@ -108,7 +138,7 @@ export function convertCurl(rawData: string) {
108138
109139 if ( op ?. startsWith ( '$' ) ) {
110140 // Handle the case where literal like -H $'Header: \'Some Quoted Thing\''
111- const str = op . slice ( 2 , op . length - 1 ) . replace ( / \\ ' / g , "'" ) ;
141+ const str = decodeShellString ( op . slice ( 2 , op . length - 1 ) ) ;
112142
113143 currentCommand . push ( str ) ;
114144 continue ;
0 commit comments