apache / apache/cordova-plugin-file

FileReader splits special characters up which leads to exception and null result

Open
#562 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
744
Forks
754
Avg merge
3d 4h
Merged PRs (30d)
1

Description

# Bug Report

### What is expected to happen?
The FileReader should read a file correctly.

### What does actually happen?
FileReader returns null

## Information
Today i noticed a special case where I was reading a JSON file with the FileReader. It returned null for some reason. When I made a small change to the file it worked. I debugged into it and found out that the FileReader has this READ_CHUNK_SIZE. It splits the file into chunks while reading. At some point it creates a string out if the byte buffer again. At this point the exception occures as the reader read just half of a special character into the buffer. Thats because special UTF-8 characters can be represented by more than one byte. In my case it was a degree sign "°".

Contributor guide

Open the contributing guide

Research direction

Start by locating FileReader and the READ_CHUNK_SIZE handling in the plugin. Reproduce the issue with a JSON file containing a multibyte character such as "°" and trace the chunk boundary that causes the exception. Done means the complete file is read without an exception and FileReader no longer returns null.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.