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

Don't escape certain non-ascii characters #486

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

daniloegea
Copy link
Collaborator

@daniloegea daniloegea commented Jul 2, 2024

Description

g_strescape will mess up with utf-8 characters. It happens because all the range from 0x7f to 0xff are escaped by default. The bytes in this range can be found in utf-8 code points so non-ascii strings will end being changed.

This PR adds all the range in the exception list.

For example, the file below:

network:
  renderer: NetworkManager
  wifis:
    wlan0:
      access-points:
        "áááÁÁÁ":
          password: "áéí"
        "normal":
          password: "á\né\tí\rÁ"

will become this (output from netplan get):

network:
  version: 2
  renderer: NetworkManager
  wifis:
    wlan0:
      access-points:
        "\\303\\241\\303\\241\\303\\241\\303\\201\\303\\201\\303\\201":
          auth:
            key-management: "psk"
            password: "\\303\\241\\303\\251\\303\\255"
        "normal":
          auth:
            key-management: "psk"
            password: "\\303\\241\\n\\303\\251\\t\\303\\255\\r\\303\\201"

With the new exceptions it will become:

network:
  version: 2
  renderer: NetworkManager
  wifis:
    wlan0:
      access-points:
        "normal":
          auth:
            key-management: "psk"
            password: "á\\né\\tí\\rÁ"
        "áááÁÁÁ":
          auth:
            key-management: "psk"
            password: "áéí"

Checklist

  • Runs make check successfully.
  • Retains 100% code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad.

@daniloegea daniloegea changed the title WIP: Utf8 strescape Don't escape certain non-ascii characters Jul 2, 2024
@daniloegea daniloegea marked this pull request as ready for review July 2, 2024 17:31
@daniloegea daniloegea requested a review from slyon July 2, 2024 17:31
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine overall, but we might whitelist some control characters that we don't want to have un-escaped (like DELETE). Can you please clarify on this?

And maybe also add a small unit-test around it, so that we can see the actual characters being used?

src/parse.c Outdated Show resolved Hide resolved
g_strescape will transform utf-8 strings in a sequence of escaped octal
numbers in form of a string. That happens because g_strescape will
escape the range from 0x7f to 0xff.

For example, "áéí" will become "\\303\\241\\303\\251\\303\\255". Pure
ASCII strings are not affected by it.

Add all the range 0x7f-0xff to the exception list.
@daniloegea
Copy link
Collaborator Author

I removed 0x7f from the list and rebased. I also added a unittest using the wifi password.

@daniloegea daniloegea requested a review from slyon July 3, 2024 09:43
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@slyon slyon merged commit 9e76feb into canonical:main Jul 3, 2024
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants