Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update tests to use new encoding
  • Loading branch information
FlafyDev committed May 26, 2022
commit 0b61f9ceb9c9973b53cc4af6cb6b6296d2f123ee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';
import 'dart:html';
import 'dart:typed_data';

Expand Down Expand Up @@ -64,7 +65,11 @@ void main() {
// Run
controller.loadHtmlString('test html');
// Verify
verify(mockElement.src = 'data:text/html,${Uri.encodeFull('test html')}');
verify(mockElement.src = Uri.dataFromString(
'test html',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These test cases don't actually exercise the problem described in your issue. Would either of these even fail if you reverted the non-test changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests wouldn't pass before this PR's changes because instead of starting the src's value with data:text/html, it now starts with data:text/html;charset=utf-8.

It would be more accurate for the test to only check if the mockElement.src starts with data:text/html;charset=utf-8, I guess. But I don't know how to do it with mock tests or if it's even necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test failure would have nothing to do with the issue you fixed. I could make these tests pass without fixing the bug by just adding ;charset=utf-8 into the interpolated string.

The issue you are fixing is about properly escaping special characters--specifically # in your examples--so that's what the test should be verifying.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(In fact, the changelog should say "incorrect escaping", not "unreliable encoding", since this is about escaping rather than encoding.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right I'll fix the test to include the new escaping. But should it be renamed to only fix escaping even though it adds the ;charset=utf-8?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to also mention adding explicit encoding as a secondary change, feel free. But there have been zero reports of encoding issues so it's not particularly important to mention.

mimeType: 'text/html',
encoding: Encoding.getByName('utf-8'),
).toString());
});

group('loadRequest', () {
Expand Down Expand Up @@ -122,8 +127,11 @@ void main() {
requestHeaders: <String, String>{'Foo': 'Bar'},
sendData: Uint8List.fromList('test body'.codeUnits),
));
verify(
mockElement.src = 'data:text/plain,${Uri.encodeFull('test data')}');
verify(mockElement.src = Uri.dataFromString(
'test data',
mimeType: 'text/plain',
encoding: Encoding.getByName('utf-8'),
).toString());
});
});
});
Expand Down