Snippets corrupt values with backslashes/quotes/+ and & or non-ASCII bodies; node axios/fetch snippets don't run
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, nodejs, python, shell
- 領域
- devtools
研究方向
The bugs sit in several target generators: string-literal escaping in the javascript fetch, axios and xhr targets and the node native, axios and fetch targets, the url-encoding choice in src/targets/shell/curl/client.ts (around lines 143-151), and the body encoding in the python http.client and requests targets. Start by reproducing one case from the issue with a local echo server. Done means each affected snippet round-trips its values and the node snippets run as generated.
由索引模型根據 Issue 內容生成。
描述
I ran the generated snippets against a local echo server and compared what arrived with the HAR. shell:wget, ruby:native and go:native round-tripped every value; the cases below did not.
// npm i [email protected]
const {HTTPSnippet} = require("httpsnippet");
const base = {method: "POST", url: "http://localhost:3000/p", headers: [], queryString: [], cookies: [], httpVersion: "HTTP/1.1"};
const gen = (h, t, c) => console.log(new HTTPSnippet({...base, ...h}).convert(t, c));
gen({postData: {mimeType: "application/json", text: JSON.stringify({path: "C:\\temp", q: 'say "hi"'})}}, "javascript", "fetch");
// body: '{"path":"C:\\temp","q":"say \"hi\""}' -> sends {"path":"C:\temp","q":"say "hi""} (invalid JSON)
gen({queryString: [{name: "name", value: "O'Brien"}]}, "javascript", "fetch");
// const url = 'http://localhost:3000/p?name=O'Brien'; -> SyntaxError
gen({postData: {mimeType: "application/x-www-form-urlencoded", params: [{name: "expr", value: "1+1"}, {name: "q", value: "a&b=c"}]}}, "shell", "curl");
// --data 'expr=1+1' --data 'q=a&b=c' -> server reads expr="1 1", q="a", b="c"
gen({postData: {mimeType: "application/json", text: JSON.stringify({city: "東京"})}}, "python", "python3");
// payload = "{\"city\":\"東京\"}"; conn.request(...) -> UnicodeEncodeError: 'latin-1' codec
gen({postData: {mimeType: "application/x-www-form-urlencoded", params: [{name: "path", value: "C:\\temp"}]}}, "python", "requests");
// payload = { "path": "C:\temp" } -> sends a TAB
1. JS string literals don't escape backslashes, and some don't escape '. In javascript:fetch, javascript:axios, javascript:xhr, node:native and node:axios, a value a\b is emitted as 'a\b' (a backspace), a\nb becomes a newline (and Node rejects it as a header value), and a JSON body with \" turns into invalid JSON. A ' in the query string or body produces a syntax error in javascript:fetch, node:fetch and javascript:xhr (ruby:faraday has the same problem with the query string). Expected the literal to evaluate to the original value.
2. shell:curl sends url-encoded form values unencoded. --data-urlencode is only chosen when the name needs encoding (the fix for #197), so a value with +, &, = or % under a plain name is sent raw: 1+1 arrives as 1 1, and a&b=c becomes an extra field.
3. python:python3 and python:requests fail on non-Latin-1 bodies. The body is passed as a str, which http.client encodes as ISO-8859-1, so 東京 raises UnicodeEncodeError and é is sent as the single byte 0xE9 instead of UTF-8. Encoding the payload (payload.encode("utf-8")) would fix it. Separately, python:requests builds form/JSON payload dicts without escaping backslashes ("C:\temp" above).
4. node:axios and node:fetch mix require() with top-level await. The output (const axios = require('axios').default; ... const { data } = await axios.request(options);) is a SyntaxError as CommonJS and a ReferenceError (require is not defined) as an ES module, so it can't run as generated.
Version: [email protected] (npm latest); same generator code on master 795d98e (e.g. src/targets/shell/curl/client.ts lines 143-151).
Credit: https://ucsbplse.github.io/
- 主要語言
- TypeScript
- 星號
- 1.2k
- 分支
- 245
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
Kong/httpsnippet 的其他 Issue
-
難度 1/5 1 小時以內 新手友好度 62/100
Kong/httpsnippet#356 ·
-
難度 3/5 1-2 天 新手友好度 35/100
Kong/httpsnippet#389 ·
-
難度 5/5 一週以上 新手友好度 25/100
Kong/httpsnippet#383 ·
-
Bug: R Code Generation Does Not Quote Parameters with Special Characters (e.g., `codes[]`)可能已有人在做 @abansal21 於 499 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 35/100
Kong/httpsnippet#379 ·
-
難度 3/5 1-2 天 新手友好度 48/100
Kong/httpsnippet#370 ·
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 82/100
garrytan/gbrain#10437 · 1 則留言 ·
維護者通常 1 天內回覆
-
Bedrock "Too many tokens" throttle is not auto-retried, unlike "Too many requests"可能已有人在做 @acmerfight 今天認領。 未關閉untriaged
難度 2/5 1-3 小時 新手友好度 78/100
earendil-works/pi#12573 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
agentes-chat/agentes-chat#1506 ·
維護者通常 1 天內回覆
-
comp/desktop desktop/files os/windows P2 type/perf
難度 2/5 1-3 小時 新手友好度 80/100
NousResearch/hermes-agent#160359 ·
維護者通常 1 天內回覆
-
Missing repro Platform: Android
難度 2/5 1-3 小時 新手友好度 76/100
software-mansion/react-native-reanimated#11554 · 1 則留言 ·
維護者通常 1 天內回覆