Skip to content

@linaria/postcss-linaria: fixers double source backslashes in the field they rewrite #1508

Description

@aki05162525

Environment

  • @linaria/postcss-linaria: master (c7b0360e)
  • PostCSS: 8.4.31
  • Node.js: 24.16.0
  • OS: macOS

Description

Follow-up to #1497, as promised there.

The fix compares each field against its source snapshot, so a field nothing touches keeps its backslashes. When a fixer rewrites a field that also contains a source-derived escape, the whole field counts as changed and the untouched escape gets escaped again — the same corruption as #1497, with a narrower trigger.

Reproduction

sample.style.ts:

import { css } from '@linaria/core';

export const style = css`
  .foo {
    content: '\u2022';
  }
`;
const { readFileSync } = require('fs');
const syntax = require('@linaria/postcss-linaria');

const source = readFileSync('sample.style.ts', 'utf8');
const doc = syntax.parse(source, { from: 'sample.style.ts' });

// stand-in for a fixer that rewrites the value — here only the quote style
doc.walkDecls((decl) => {
  decl.value = decl.value.replace(/'/g, '"');
});

let out = '';
syntax.stringify(doc, (s) => {
  out += s;
});
console.log(out);

Expected:

content: "\u2022";

Actual:

content: "\\u2022";

Skipping the walkDecls call leaves '\u2022' intact, so this only happens when a fixer writes to the same field.

In practice it is reached by any fixable rule that rewrites a value or a selector containing a backslash — quote normalisation over content: '\u2022', or a selector fixer touching a selector that contains \:.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug report 🦗Issue is probably a bug, but it needs to be checkedneeds: complete repro 🖥️Issue need to have complete repro provided

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions