Snippets corrupt values with backslashes/quotes/+ and & or non-ASCII bodies; node axios/fetch snippets don't run
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- javascript, nodejs, python, shell
- Domínio
- devtools
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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/
- Linguagem predominante
- TypeScript
- Estrelas
- 1.2k
- Forks
- 245
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de Kong/httpsnippet
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 62/100
Kong/httpsnippet#356 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
Kong/httpsnippet#389 ·
-
Support for Oracle APEXAberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
Kong/httpsnippet#383 ·
-
Bug: R Code Generation Does Not Quote Parameters with Special Characters (e.g., `codes[]`)Talvez já em andamento @abansal21 assumiu há 499 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
Kong/httpsnippet#379 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 48/100
Kong/httpsnippet#370 ·
Todas as issues de Kong/httpsnippet
Issues semelhantes
-
Postgres upgrade golden leaves fixture URL query parameters in the expected output comparisonAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
garrytan/gbrain#10437 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Bedrock "Too many tokens" throttle is not auto-retried, unlike "Too many requests"Talvez já em andamento @acmerfight assumiu hoje. Abertauntriaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
earendil-works/pi#12573 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
agentes-chat/agentes-chat#1506 ·
Mantenedores costumam responder em até 1 dia
-
comp/desktop desktop/files os/windows P2 type/perf
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
NousResearch/hermes-agent#160359 ·
Mantenedores costumam responder em até 1 dia
-
Missing repro Platform: Android
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
software-mansion/react-native-reanimated#11554 · 1 comentário ·
Mantenedores costumam responder em até 1 dia