fix(redirects): respect quoted CSV fields and read the type case-insensitively - #521
Draft
igoramf wants to merge 1 commit into
Draft
fix(redirects): respect quoted CSV fields and read the type case-insensitively#521igoramf wants to merge 1 commit into
igoramf wants to merge 1 commit into
Conversation
…nsitively
Two independent parsing bugs found while investigating a redirect loop; neither
causes the loop, both corrupt real data.
Quoted fields: `parseRedirectsCsv` split on every comma, but bulk exports quote
rows whose query contains one:
"https://site/relogios?map=category-1,category-2",/relogios,PERMANENT
That row parsed as from=`/"https://site/relogios?map=category-1`,
to=`category-2"`. In one production CSV, 643 of 3017 rows came out with a
fragment of a query as their target (`to: "c"`, `to: "priceFrom"`). They are
inert today only because the mangled source never matches a request.
Type spelling: only lowercase `permanent` mapped to 301. Exports commonly write
`PERMANENT`, so every one of that site's ~3000 redirects served 302 — a
temporary redirect passes no ranking signal to the new URL, silently discarding
the SEO value of the migration.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dois bugs de parsing achados investigando um loop de redirect. Nenhum dos dois causa o loop (isso é o #519) e nenhum depende do outro — mas os dois corrompem dado real, e são pequenos o bastante para irem juntos.
Independente do #519 e do #520; pode mergear em qualquer ordem. Encosta em
parseRedirectsCsv, então espere um conflito trivial com o #519.1.
split(",")ignorava aspasExports de redirect em massa citam linhas cuja query contém vírgula — o padrão de URL de categoria do VTEX:
O split cru quebrava nas vírgulas de dentro das aspas, produzindo:
Num CSV de produção, 643 das 3017 linhas saíram assim, com um pedaço da query como destino:
to: "c",to: "priceFrom",to: "specificationFilter_29". Hoje elas são inofensivas só por acidente — a origem mutilada (/"https://…) nunca casa com request nenhuma. Mas é 1/5 do arquivo virando lixo silencioso, e a próxima linha citada que não comece comhttpvira uma regra ativa apontando para um destino inventado.Agora o split respeita aspas, incluindo
""escapado (RFC 4180).2.
PERMANENTvirava 302Exports escrevem
PERMANENTem caixa alta. Como só a grafia minúscula casava, todos os ~3000 redirects daquele site serviam 302. Redirect temporário não passa sinal de ranking para a URL nova — a migração inteira jogou fora o valor de SEO das URLs antigas, sem erro nenhum em log.Agora o tipo é lido sem diferenciar caixa, no CSV e nos blocos de CMS.
Testes
packages/blocks/src/sdk/redirectsCsvParsing.test.ts, 8 casos. 5 falham nomain:Um dos casos documenta a fronteira em vez de esconder: uma linha sem aspas cuja query tem vírgula continua sendo picada. Aspas são o que torna a vírgula literal; adivinhar seria pior que falhar.
Suíte do pacote: 746 passed (56 arquivos).
Contexto
🤖 Generated with Claude Code
Summary by cubic
Fixes two independent bugs in
parseRedirectsCsv— quoted CSV fields were split on commas inside quotes, and uppercasePERMANENTredirect types were served as 302.""is unescaped per RFC 4180; previously, 643 of 3017 rows in one production export had a query fragment as their target.PERMANENT,Permanent,permanent, and301all map to 301, in both CSV and CMS block redirects.Written for commit 59f5477. Summary will update on new commits.