Skip to content

Append action removes literal "$`" due to special replacement pattern handling #465

@checche

Description

@checche

Description:

When using the append action in Plop, if the target file already contains the literal "$`"(dollar + backquote), it gets removed during the append operation. This issue appears to occur in the implementation of the append action, where String.replace interprets "$" as a special replacement pattern (representing the text preceding the match) rather than as a literal string.

The problem is placed when regular expression strings are written in JavaScript source code.

Steps to Reproduce:

input.txt

$`$`

plopfile.ts

import type { NodePlopAPI } from "plop";

export default function (plop: NodePlopAPI) {
  plop.setGenerator("test", {
    description: "test",
    prompts: [
      {
        type: "input",
        name: "name",
        message: "input name",
      },
    ],
    actions: [
      {
        type: "append",
        path: "input.txt",
        template: 'console.log("{{name}}");',
      },
    ],
  });
}

Actual Outcome

console.log("hoge");

Additional Context:

The issue seems to be in the implementation of the append action logic in append.js A potential fix might involve escaping all $ characters (e.g., replacing $ with $$) in the replacement string to ensure they remain intact.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions