WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
87578
[FileAPI] The result attribute of FileReader should use null to replace empty string
https://bugs.webkit.org/show_bug.cgi?id=87578
Summary
[FileAPI] The result attribute of FileReader should use null to replace empty...
Li Yin
Reported
2012-05-26 08:31:45 PDT
From Spec:
http://www.w3.org/TR/FileAPI/#filedata-attr
The list below is normative for the result attribute and is the conformance criteria for this attribute: On getting, if the readyState is EMPTY (no read method has been called) then the result attribute MUST return null. On getting, if an error in reading the File or Blob has occurred (using any read method), then the result attribute MUST return null. Currently, WebKit uses string "", not use null. We should keep the conformance with the spec.
Attachments
Patch
(10.08 KB, patch)
2012-05-26 11:01 PDT
,
Li Yin
no flags
Details
Formatted Diff
Diff
Patch
(10.19 KB, patch)
2012-05-26 16:28 PDT
,
Li Yin
no flags
Details
Formatted Diff
Diff
Patch
(7.55 KB, patch)
2012-05-29 20:28 PDT
,
Li Yin
no flags
Details
Formatted Diff
Diff
Patch
(8.32 KB, patch)
2012-05-29 22:48 PDT
,
Li Yin
no flags
Details
Formatted Diff
Diff
Show Obsolete
(3)
View All
Add attachment
proposed patch, testcase, etc.
Li Yin
Comment 1
2012-05-26 11:01:58 PDT
Created
attachment 144205
[details]
Patch
Kentaro Hara
Comment 2
2012-05-26 15:05:45 PDT
Comment on
attachment 144205
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=144205&action=review
> Source/WebCore/ChangeLog:12 > + WebKit should change the returned value empty string into null to keep > + conformance with the spec.
What are the behaviors of other browsers? We want to also keep cross-browser compatibility.
> Source/WebCore/fileapi/FileReader.cpp:248 > + if (ret == "")
ret.IsEmpty() would be better.
> LayoutTests/fast/files/resources/read-common.js:174 > + if (result == null) {
Please use === instead of ==. == in JavaScript is "ambiguous" and thus not suitable for testing purpose.
> LayoutTests/fast/files/resources/read-common.js:176 > + return ;
Nit: No space needed before ';'
Li Yin
Comment 3
2012-05-26 16:17:41 PDT
(In reply to
comment #2
)
> (From update of
attachment 144205
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=144205&action=review
> > > Source/WebCore/ChangeLog:12 > > + WebKit should change the returned value empty string into null to keep > > + conformance with the spec. > > What are the behaviors of other browsers? We want to also keep cross-browser compatibility. >
Currently, Firefox 11, Opera 11, IE 10 follows the standard. Webkit based browsers don't. Thanks for your review.
Li Yin
Comment 4
2012-05-26 16:28:19 PDT
Created
attachment 144210
[details]
Patch
Li Yin
Comment 5
2012-05-26 16:36:16 PDT
You can get the test result from
http://samples.msdn.microsoft.com/ietestcenter/fileapi/fileapi_harness.htm
Test Method: Click the "Net" button three times, enter Test 3/3. Directly click "Run Test" button, the 14th sub-test can verify the feature.
Li Yin
Comment 6
2012-05-26 17:37:10 PDT
I think using null should be more resonable, because empty string will confuse developers when reading a empty file.
Kentaro Hara
Comment 7
2012-05-26 18:02:58 PDT
Comment on
attachment 144210
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=144210&action=review
> Source/WebCore/ChangeLog:15 > + Currently, Firefox, Opera and IE 10 follows the spec, but Webkit based > + browser don't. > + WebKit should change the returned value empty string into null to keep > + conformance with the spec.
Thanks for the clarification. Then the fix looks reasonable.
WebKit Review Bot
Comment 8
2012-05-26 18:51:21 PDT
Comment on
attachment 144210
[details]
Patch Clearing flags on attachment: 144210 Committed
r118620
: <
http://trac.webkit.org/changeset/118620
>
WebKit Review Bot
Comment 9
2012-05-26 18:51:26 PDT
All reviewed patches have been landed. Closing bug.
Jian Li
Comment 10
2012-05-29 10:36:45 PDT
Comment on
attachment 144210
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=144210&action=review
> Source/WebCore/fileapi/FileReader.cpp:248 > + if (ret.isEmpty())
This would cause NULL being returned when reading an empty file. I think you should change it to: if (m_loader && m_loader->stringResult()) return m_loader->stringResult(); return String();
> LayoutTests/fast/files/blob-slice-test-expected.txt:3 > +Slicing from 2 to 2: null
The spec does not say that null needs to be returned for empty file/blob. I think we should still return empty string for this case. You could add test cases to cover the scenarios that result is being read when readyState is EMPTY or an error occurs.
Jian Li
Comment 11
2012-05-29 11:00:53 PDT
I verify that Firefox 12 returns empty string for result when reading an empty file.
WebKit Review Bot
Comment 12
2012-05-29 11:12:18 PDT
Re-opened since this is blocked by 87760
Li Yin
Comment 13
2012-05-29 18:29:08 PDT
> > Source/WebCore/fileapi/FileReader.cpp:248 > > + if (ret.isEmpty()) > > This would cause NULL being returned when reading an empty file. I think you should change it to: > if (m_loader && m_loader->stringResult()) > return m_loader->stringResult(); > return String(); >
When the m_loader is Null or the error is occurred, both of them should return null. So I think the right change shoule be: if (!m_loader || m_error) return String(); return m_loader->stringResult; MeanWhile, the arrayBufferResult should be changed too. if (!m_loader || m_error) return 0; return m_loader->arrayBufferResult(); Thanks for reporting this regression.
Li Yin
Comment 14
2012-05-29 20:28:02 PDT
Created
attachment 144686
[details]
Patch
Jian Li
Comment 15
2012-05-29 22:12:26 PDT
Comment on
attachment 144686
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=144686&action=review
> Source/WebCore/ChangeLog:10 > + Or if an error in reading the File or Blob has occurred (using any read method),
nit: two "if" can be concatenated like If the readyState is EMPTY (...) or an error occurs ...
> Source/WebCore/ChangeLog:17 > +
nit: extra empty line is not needed.
> LayoutTests/fast/files/resources/read-file-test-cases.js:221 > + log("result before calling reading method: " + readerToTestReread.result)
Why is this check being added to this test testReadAgainAfterFailedReadStep1? Why not adding a new async test case like testResultBeforeRead?
Li Yin
Comment 16
2012-05-29 22:48:46 PDT
Created
attachment 144705
[details]
Patch
Li Yin
Comment 17
2012-05-29 22:50:42 PDT
(In reply to
comment #15
)
> nit: two "if" can be concatenated like If the readyState is EMPTY (...) or an error occurs ...
Done
> > > Source/WebCore/ChangeLog:17 > > + > > nit: extra empty line is not needed.
> Done
> > LayoutTests/fast/files/resources/read-file-test-cases.js:221 > > + log("result before calling reading method: " + readerToTestReread.result) > > Why is this check being added to this test testReadAgainAfterFailedReadStep1? Why not adding a new async test case like testResultBeforeRead?
Done. Thanks for your review.
WebKit Review Bot
Comment 18
2012-05-29 23:34:37 PDT
Comment on
attachment 144705
[details]
Patch Clearing flags on attachment: 144705 Committed
r118897
: <
http://trac.webkit.org/changeset/118897
>
WebKit Review Bot
Comment 19
2012-05-29 23:34:50 PDT
All reviewed patches have been landed. Closing bug.
Alexey Proskuryakov
Comment 20
2012-05-30 11:08:35 PDT
Mac buildbot was seeing failures on read-blob-async.html. These did not look platform specific (additional lines in output), so I updated cross platform results: <
http://trac.webkit.org/changeset/118940
>.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug