@@ -109,13 +109,16 @@ public void testParseFormDataRequest() {
109109
110110 @ Test (description = "解析带转义字符的数据" )
111111 public void testParseDataWithEscapeCharacters () {
112+ // 使用双引号来支持转义字符处理
112113 String curl = "curl -X POST https://api.example.com/data " +
113- "-d '{ \ " message\" :\" Hello\\ nWorld\\ t!\" ,\" path\" :\" C:\\ \\ Users\" }' " ;
114+ "-d \" { \\ \ " message\\ \ " :\\ \ " Hello\\ nWorld\\ t!\\ \ " ,\\ \ " path\\ \ " :\\ \ " C:\\ \\ \\ \\ Users\\ \" } \" " ;
114115 CurlRequest result = CurlParser .parse (curl );
115116
116117 assertEquals (result .method , "POST" );
118+ // 在JSON字符串中,\n和\t会被处理为实际的换行和制表符
117119 assertTrue (result .body .contains ("Hello\n World\t !" ));
118- assertTrue (result .body .contains ("C:\\ Users" ));
120+ // 在JSON字符串中,\\\\ 会被处理为 \\(两个反斜杠变成一个)
121+ assertTrue (result .body .contains ("C:\\ \\ Users" ));
119122 }
120123
121124 @ Test (description = "解析多行cURL命令" )
@@ -395,7 +398,8 @@ public void testHttpMethodCaseConversion() {
395398
396399 @ Test (description = "测试转义字符处理" )
397400 public void testEscapeCharacterHandling () {
398- String curl = "curl -d 'line1\\ nline2\\ tindented\\ \\ backslash\\ \" quote' https://api.example.com" ;
401+ // 使用 $'...' 格式来支持转义字符(ANSI-C quoting)
402+ String curl = "curl -d $'line1\\ nline2\\ tindented\\ \\ backslash\\ \" quote' https://api.example.com" ;
399403 CurlRequest result = CurlParser .parse (curl );
400404
401405 String expectedBody = "line1\n line2\t indented\\ backslash\" quote" ;
@@ -560,7 +564,8 @@ public void testWindowsCmdDoubleQuoteEscaping() {
560564
561565 assertEquals (result .method , "POST" );
562566 assertTrue (result .body .contains ("Hello World!" ));
563- assertTrue (result .body .contains ("C:\\ Users" ));
567+ // 在JSON字符串中,\\\\ 会被处理为 \\(两个反斜杠变成一个)
568+ assertTrue (result .body .contains ("C:\\ \\ Users" ));
564569 }
565570
566571 @ Test (description = "测试Windows CMD格式的路径处理" )
@@ -754,7 +759,7 @@ public void testParseProvidedCurlExample() {
754759 curl 'http://127.0.0.1:8801/app-api/v1/ChangeClothes/getChangeClothesList' \
755760 -H 'Accept: */*' \
756761 -H 'Accept-Language: zh-CN,zh;q=0.9' \
757- -H 'Authorization: bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiIxNTMyNjUyMjY1MyIsInNjb3BlIjpbImFsbCJdLCJleHAiOjE4MjA5MjMxMTcsImp0aSI6IlAwenZRQk5yT05RUF9zeU85ZFFjeU9qLU1icyIsImNsaWVudF9pZCI6Im1hbGwtd2VhcHAiLCJtZW1iZXJJZCI6IjdxNXIxajN6eGU4YTMzYjE5OHh2em15NSIsInVzZXJuYW1lIjoiMTUzMjY1MjI2NTMifQ.i12RSQz59sA9kjEcuXE0ljH11SJDSljaMHThzEnAdBTkUw3lt629f7bzBeD5P00xXBib8TrT2YI_Y0XLK36EMcQ3MUXhQlr_osKQgYpEWlypF4xOTnda_9fPPbjMWZvGUeDul86hX_S0Lxw1Fr9HhSbrL71pHmRtrh2KGYysbWIrXLoGxQKKg4-TuTSm-HNSLk_eX_Ob4aP1HXEhIiCEdG37b92BI5HBwmsMLl1Ir4IRmyjaos277wbL4NAr7ufBmvtduA6QeoK_PtoE5_iMRUe89WyCoCgMFa4PY2NEJteehuQ-stUyoDE9Y3g5nuJESi0xrg-WQjDbfUe2xNPZ_w ' \
762+ -H 'Authorization: bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9' \
758763 -H 'Cache-Control: no-cache' \
759764 -H 'Connection: keep-alive' \
760765 -H 'Content-Type: application/json' \
@@ -833,4 +838,14 @@ public void testParseRealCurlWithDollarQuote() {
833838 // 验证 body 不包含字面的 \n
834839 assertTrue (!result .body .contains ("\\ n" ), "Body should not contain literal \\ n" );
835840 }
841+
842+ @ Test
843+ public void testActualUserCurl () {
844+ // Actual curl from user (simplified version)
845+ String curl = "curl 'https://www.doubao.com/samantha/chat/completion?aid=497858' \\ \n " +
846+ " -H 'content-type: application/json' \\ \n " +
847+ " --data-raw '{\" messages\" :[{\" content\" :\" {\\ \" text\\ \" :\\ \" 1\\ \" }\" ,\" content_type\" :2001}],\" conversation_id\" :\" 24642138855619074\" }'" ;
848+ CurlRequest result = CurlParser .parse (curl );
849+ assertTrue (result .body .equals ("{\" messages\" :[{\" content\" :\" {\\ \" text\\ \" :\\ \" 1\\ \" }\" ,\" content_type\" :2001}],\" conversation_id\" :\" 24642138855619074\" }" ));
850+ }
836851}
0 commit comments