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

Data from file is not escaped for json #2

Open
aqos156 opened this issue Oct 27, 2021 · 2 comments
Open

Data from file is not escaped for json #2

aqos156 opened this issue Oct 27, 2021 · 2 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers
Milestone

Comments

@aqos156
Copy link

aqos156 commented Oct 27, 2021

As the title says, data from the file are not formatted for json. Any double quotes or backslashes will break the json formatting. I have to do this with sed manually for each logfile.

sed 's/\\\\/\\\\\\\\/g' file.log | sed 's/"/\\\\"/g' > file-out.log

The formatting of sed backslashes is weird because of drone.yml also escapes backslashes.

Complete working escaping step:

- name: Escape json
  image: alpine
  commands:
    - sed 's/\\\\/\\\\\\\\/g' output.log | sed 's/"/\\\\"/g' > output-out.log

I would suggest to use a kind of json escaping library, I do not know if my solution of replacing just \ with \\ and " with \" has any edge cases.

@DefinitelyADev DefinitelyADev added this to the v2.0.0 milestone Oct 27, 2021
@DefinitelyADev DefinitelyADev self-assigned this Oct 27, 2021
@DefinitelyADev DefinitelyADev added bug Something isn't working good first issue Good for newcomers labels Oct 27, 2021
@aqos156
Copy link
Author

aqos156 commented Dec 20, 2022

@DefinitelyADev would System.Web.HttpUtility.JavaScriptStringEncode be a good solution? It's a one line change that would be very helpful.

@DefinitelyADev
Copy link
Owner

I'll take a look at it, sorry I have not been very active. I am preparing v2 that will solve those issues and be more input agnostic. This version of the plugin was made as a necessity for a specific use case.

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

No branches or pull requests

2 participants