reciper
reciper copied to clipboard
Fix encoding when importing recipies
Summary
Fix to import functionality when importing recipies that contain "special" characters.
Changes
- Use
XFile.readAsBytes()
andEncoding.decode(...)
instead ofXFile.readAsString()
in function userImport of class Utils- I have no previous experience with Dart so I have no idea why
XFile.readAsString()
didn't work :sweat_smile:
- I have no previous experience with Dart so I have no idea why
- Change file writing code in function userExport of class Utils so that it uses
Encoding.encode(...)
andFile.writeAsBytes()
(this change is just for consistency) - Added some missing(?)
await
keywords to the import and export functions- The file export would sometimes just export an empty file, so that might have been an issue with the async code. Not sure. :thinking: Again, this is my first time using Dart so I might be wrong
Detailed problem description
Encoding seemed to break when recipies with certain special characters were imported (e.g. characters that are used in other languages besides English). Steps to reproduce:
- Create a new recipe
- Add with some non-English characters (like åäö) to one or all of the text fields
- Or copy-paste the test data at the end of this PR description)
- Save the recipe
- Go to "Settings" -> "Export recipies" and export the data (e.g. to Google Drive)
- Go to "Home" and delete the test recipe
- Go to "Settings" -> "Import recipies" and import the file that was exported in step 4
- Go to "Home" and view the recipe => the non-English characters are not the same
I created a test recipe to demonstrate the issue:
Initial test recipe (image)
When recipies were exported (e.g. to Google Drive), deleted from Reciper and imported back, this was the result:
Imported broken recipe (image)
I viewed the exported json file and its contents were fine:
[["Recipes"],[[{"id":27,"steps":"-","title":"Encoding test","servings":"1","ingredients":"Numbers: 123\nLower case characters: abc\nUpper case characters: ABC\n\nLower case DK/FI/NO/SE characters: åäöæø\nUpper case DK/FI/NO/SE letters: ÅÄÖÆØ\n\nLower case IS characters: áðéíóúýþ\nUpper case IS characters: ÁÐÉÍÓÚÝÞ\n\nLower case DE characters: ßü\nUpper case DE characters: ẞÜ\n\nLower case FR characters: àâçèêëîïôœùûÿ\nUpper case FR characters: ÀÂÇÈÊËÎÏÔŒÙÛŸ\n\nRandom emojis: 😊🤣😎🍕🍔🥗🍝\n\nRandom kaomojis: (●'◡'●) ᓚᘏᗢ (╯°□°)╯︵ ┻━┻","source":""}]]]
Here's the text for the recipe that I used to initially create the recipe in the UI (can be just copy-pasted into the Ingredients field):
Data for creating the test recipe
Numbers: 123
Lower case characters: abc
Upper case characters: ABC
Lower case DK/FI/NO/SE characters: åäöæø
Upper case DK/FI/NO/SE letters: ÅÄÖÆØ
Lower case IS characters: áðéíóúýþ
Upper case IS characters: ÁÐÉÍÓÚÝÞ
Lower case DE characters: ßü
Upper case DE characters: ẞÜ
Lower case FR characters: àâçèêëîïôœùûÿ
Upper case FR characters: ÀÂÇÈÊËÎÏÔŒÙÛŸ
Random emojis:
😊🤣😎🍕🍔🥗🍝
Random kaomojis:
(●'◡'●)
ᓚᘏᗢ
(╯°□°)╯︵ ┻━┻
Feel free to ask questions or request changes!