clemg / pythongolfer

Code golfer and minifier for Python https://clemg.github.io/pythongolfer/
https://clemg.github.io/pythongolfer/
GNU General Public License v3.0
33 stars 5 forks source link

Reversed coated string in result code #2

Open clemg opened 3 years ago

clemg commented 3 years ago

Describe the bug When the input code contains ". ", the coating code is reversed and sometimes appears in the middle. For some reasons, it does not happen every time, it depends on the position of the ". " string.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://clemg.github.io/pythongolfer/
  2. Enter a code with ". " in it
  3. Click the "Golf it!" button
  4. See error

Expected behavior The result code should appear coated with the decoding python code, but instead we get a reversed string in the middle.

Screenshots

Desktop or Smartphone (please complete the following information):

Edit: also works with "+ " in it. Theory: Maybe when the "+" or the "." is in an even indice position in the string, the converted char in UTF-16 is a reversing one, it would explain what this happens only in this precise case.

matytyma commented 1 year ago

In my opinion, the reason is, that it maps to a character that changes the direction of text, so it should work until pasted to some editor, that will remove such characters.

Could you try to copy the bugged result and post it somewhere on Discord? The reason why I'm suggesting it is that Discord removes text direction-changing characters).

clemg commented 1 year ago

But if the character is removed (through discord for instance) the decoded golfed code won't be the expected one, it will cause a 2 characters loss

matytyma commented 1 year ago

Yeah, the code won't work as expected after the removal, but it'll confirm what I said and show that the code is valid. It only renders from the right side, but it's not actually reversed. Haven't yet found any IDE, that would remove the character.

matytyma commented 1 year ago

But this is an actual issue: Code (Replaced the actual character U+202E (RLO) with the text '-RLO-'

print("-RLO-Lol, this is a funny test")

image

clemg commented 1 year ago

I see what you did My take on this is to leave it as is, or maybe add a bigger disclaimer when this is encountered

Removing/changing the code isn't a solution in my opinion If you have another idea, feel free to submit it 😄

matytyma commented 1 year ago

I'm too lazy to code in JavaScript, so here you're somewhat you could do:

When the code contains any of the characters specified in the link I posted above and warn the user then If the original code contains the character, warn that it might produce different strings If the golfed code contains it, warn that it only does not render well, but the code will work as expected (not in Linux terminal :sweat_smile:)