[
https://issues.apache.org/jira/browse/CB-453?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Simon MacDonald resolved CB-453.
--------------------------------
Resolution: Fixed
Return number of bytes written not the length of the string written.
> FileWriter.append - Chinese characters are not appended to the file correctly
> -----------------------------------------------------------------------------
>
> Key: CB-453
> URL: https://issues.apache.org/jira/browse/CB-453
> Project: Apache Callback
> Issue Type: Bug
> Components: Android
> Affects Versions: 1.5.0
> Environment: test("should be able to write and append to file in
> Chinese Traditional, createWriter", function() {
> QUnit.stop(Tests.TEST_TIMEOUT);
> expect(2);
> var that = this,
> fileName = "writer.chinese",
> filePath = this.root.fullPath + '/' + fileName,
> // file content
> rule = "每個規則有一個例外。",
> // for testing file length
> length = rule.length,
> // writes initial file content
> write_file = function(fileEntry) {
> fileEntry.createWriter(function(writer) {
> writer.onwriteend = function(evt) {
> // valid writing of non-ascii file was already
> validated in previous test.
> // Append to file to verify writer.length and
> writer.position are set correctly
> append_file(writer);
> };
> writer.write(rule);
> }, that.fail);
> },
> // appends to file
> append_file = function(writer) {
> var exception = " 除了這一個";
> writer.onwriteend = function(evt) {
> // read back file to verify that data was appended
> var reader = new FileReader();
> reader.onloadend = function(evt) {
> console.log("old: " + rule + exception);
> console.log("new: " + evt.target.result);
> console.log("old: " + length);
> console.log("new: " + evt.target.result.length);
>
> ok(evt.target.result === (rule + exception),
> "reader.result after append should be equal to the text written.");
> ok(evt.target.result.length === length,
> "reader.result length should equal initial length.");
> // cleanup
> //that.deleteFile(fileName);
> QUnit.start();
> };
> var myFile = new File();
> myFile.fullPath = filePath;
> reader.readAsText(myFile);
> };
> length += exception.length;
> console.log("len: " + writer.length);
> writer.seek(writer.length);
> console.log("pos: " + writer.position);
> writer.write(exception);
> };
>
> // create file, then write and append to it
> this.createFile(fileName, write_file);
> });
> Reporter: Simon MacDonald
> Assignee: Simon MacDonald
> Fix For: 1.6.0
>
>
> When Becky checked in her update to the automated file tests
> (https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-mobile-spec.git;a=commit;h=db377f9f2b4c5507b6eb1fcb8eb4fa029030cdef)
> the test to check if you could append to a file that includes Chinese
> characters started to fail. Apparently what we expect to be in the file is
> not correct.
> First write:
> Expect - "每個規則有一個例外。"
> Received - "每個規則有一個例外。"
> After append:
> Expect - "每個規則有一個例外。 除了這一個"
> Received - "每個規? 除了這一個"
> See environment section for the full test case.
> The root cause of the problem is that the FileWriter.write method returns the
> wrong number of bytes written for multi-byte language strings like Chinese
> characters.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira