Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Seemingly impossible to get a single \ to appear in generated command text. #187

Open
2 of 4 tasks
joethompson14 opened this issue Jul 12, 2023 · 1 comment
Open
2 of 4 tasks
Labels
bug Something isn't working

Comments

@joethompson14
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Code Snippet

const BACKSLASH = `\\';
 new CircleCI.Job(
    jobName,
    new CircleCI.executors.DockerExecutor('cimg/python:3.11'),
    [
      BeanstalkOrb.setupCommand({}),
      new CircleCI.commands.Run({
        command: `
          set -ex
          cat${BACKSLASH}<<EOF>options.json
            [
              { "Namespace": "aws:autoscaling:asg", "OptionName": "MinSize",
                "Value": "${minInstances}" },
              { "Namespace": "aws:autoscaling:asg", "OptionName": "MaxSize",
                "Value": "${maxInstances}" }
            ]
          EOF`
      })
  ]);

When inside of a workflow will only ever generate an even number - 0, 2, 4, ... - of backslashes in the generated configuration - no matter the amount of backslashes included in BACKSLASH. This is making it impossible to generate the above command to execute during CI as it complains there is an unclosed << tag as that is a protected char/string by CircleCI.

Minimum reproduction code

See above.

Steps to reproduce

See above.

Expected behavior

It should be possible to get a single backslash to intentionally appear in generated text.

CircleCI Config SDK version

0.12.3

Node.js version

16.13.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@joethompson14 joethompson14 added the bug Something isn't working label Jul 12, 2023
@joethompson14
Copy link
Author

This appears to be a limitation of the included yaml package - https://eemeli.org/yaml/#yaml. It seems to be impossible to get it to generate a single \ inside of a quoted string. I am also not having luck trying to force the processor to write the string as a block literal instead of a quoted string.

One solution could be to provide some sort of option to force escaping of << substrings for command literals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant