insanum / sncli

Simplenote CLI
MIT License
397 stars 35 forks source link

fixed windows style newlines in titles and note view #112

Closed lostways closed 3 years ago

lostways commented 3 years ago

I noticed that if you create notes using the Windows SImplenote app, newlines are encoded with \r\n and not \n. This causes the note titles to end in "?" and all newlines to also show a "?" in the note view.

I fixed this by using str.splitlines() instead of str.split('\n') for the note view. I also modified the regex used to determine the title of the note. It now matches all non white spaces characters that are not \r or \n.

Windows Note: new-lines-in-windows

Before Fix: before-new-line-fix

After Fix: after-new-line-fix

samuelallan72 commented 3 years ago

@lostways while you're here, could you also check other instances of .split('\n'), to see if they cause issues for you too? For example these two places:

lostways commented 3 years ago

I used the regex \r?\n to match newlines. This will match \r\n and \n.

https://stackoverflow.com/questions/1331815/regular-expression-to-match-cross-platform-newline-characters https://stackoverflow.com/questions/5583579/question-marks-in-regular-expressions

You probably don't need to worry about the other chars and I hesitate to add them to the regex without being able to reliable test how they are handled. I can use that pattern in the SO if you prefer though.

I also created a utility method get_note_lines to handle splitting the note content up.

Things to test (I tested all of these):

  1. Note list (titles)
  2. Individual note view
  3. Note Diff
  4. Note Search
  5. Note copy
lostways commented 3 years ago

Thanks @lostways ! Looks good to me. I left one request to fix, but otherwise happy to merge once that is addressed and commits are tidied. :)

Awesome! Really enjoying the app and glad I can help improve it :-)