зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1703444 - part1 : comment block should be preceded by a blank line. r=jbauman
Differential Revision: https://phabricator.services.mozilla.com/D111300
This commit is contained in:
Родитель
f10bf5a49a
Коммит
38a3d53a58
|
@ -1350,6 +1350,7 @@ XPCOMUtils.defineLazyPreferenceGetter(this, "DEBUG_LOG",
|
|||
}
|
||||
|
||||
// This parser is line-based. Let's see if we have a line to parse.
|
||||
let isPrevLineBlank = false;
|
||||
while (/\r\n|\n|\r/.test(this.buffer)) {
|
||||
let buffer = this.buffer;
|
||||
let pos = 0;
|
||||
|
@ -1369,9 +1370,19 @@ XPCOMUtils.defineLazyPreferenceGetter(this, "DEBUG_LOG",
|
|||
// Spec defined replacement.
|
||||
line = line.replace(/[\u0000]/g, "\uFFFD");
|
||||
|
||||
if (!/^NOTE($|[ \t])/.test(line)) {
|
||||
// Detect the comment. We parse line on the fly, so we only check if the
|
||||
// comment block is preceded by a blank line and won't check if it's
|
||||
// followed by another blank line.
|
||||
// https://www.w3.org/TR/webvtt1/#introduction-comments
|
||||
// TODO (1703895): according to the spec, the comment represents as a
|
||||
// comment block, so we need to refactor the parser in order to better
|
||||
// handle the comment block.
|
||||
if (isPrevLineBlank && /^NOTE($|[ \t])/.test(line)) {
|
||||
LOG("Ignore comment that starts with 'NOTE'");
|
||||
} else {
|
||||
this.parseLine(line);
|
||||
}
|
||||
isPrevLineBlank = emptyOrOnlyContainsWhiteSpaces(line);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
comment-in-cue-text
|
||||
<link rel="help" href="https://www.w3.org/TR/webvtt1/#introduction-comments">
|
||||
|
||||
assert_equals(cues.length, 2);
|
||||
|
||||
assert_equals(cues[0].text, 'NOTE text');
|
||||
assert_equals(cues[0].startTime, 0);
|
||||
assert_equals(cues[0].endTime, 1);
|
||||
|
||||
assert_equals(cues[1].text, 'NOTE text\nNOTE text2');
|
||||
assert_equals(cues[1].startTime, 1);
|
||||
assert_equals(cues[1].endTime, 2);
|
||||
|
||||
===
|
||||
WEBVTT
|
||||
|
||||
NOTE this is real comment that should be ignored
|
||||
|
||||
00:00:00.000 --> 00:00:01.000
|
||||
NOTE text
|
||||
|
||||
NOTE
|
||||
this is also a real comment that should be ignored
|
||||
this is also a real comment that should be ignored
|
||||
|
||||
00:00:01.000 --> 00:00:02.000
|
||||
NOTE text
|
||||
NOTE text2
|
|
@ -0,0 +1,47 @@
|
|||
<!doctype html>
|
||||
<!-- DO NOT EDIT! This file and support/comment-in-cue-text.vtt are generated. -->
|
||||
<!-- See /webvtt/parsing/file-parsing/README.md -->
|
||||
<meta charset=utf-8>
|
||||
<title>WebVTT parser test: comment-in-cue-text</title>
|
||||
<link rel="help" href="https://www.w3.org/TR/webvtt1/#webvtt-comment-block">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
var t = async_test('comment-in-cue-text');
|
||||
t.step(function(){
|
||||
var video = document.createElement('video');
|
||||
var track = document.createElement('track');
|
||||
assert_true('src' in track, 'track element not supported');
|
||||
track.src = 'support/comment-in-cue-text.vtt';
|
||||
track['default'] = true;
|
||||
track.kind = 'subtitles';
|
||||
track.onload = this.step_func(trackLoaded);
|
||||
track.onerror = this.step_func(trackError);
|
||||
video.appendChild(track);
|
||||
document.body.appendChild(video);
|
||||
});
|
||||
|
||||
function trackLoaded(event) {
|
||||
var track = event.target;
|
||||
var video = track.parentNode;
|
||||
var cues = video.textTracks[0].cues;
|
||||
{
|
||||
assert_equals(cues.length, 2);
|
||||
|
||||
assert_equals(cues[0].text, 'NOTE text');
|
||||
assert_equals(cues[0].startTime, 0);
|
||||
assert_equals(cues[0].endTime, 1);
|
||||
|
||||
assert_equals(cues[1].text, 'NOTE text\nNOTE text2');
|
||||
assert_equals(cues[1].startTime, 1);
|
||||
assert_equals(cues[1].endTime, 2);
|
||||
|
||||
}
|
||||
this.done();
|
||||
}
|
||||
|
||||
function trackError(e) {
|
||||
assert_unreached('got unexpected error event');
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
WEBVTT
|
||||
|
||||
NOTE this is real comment that should be ignored
|
||||
|
||||
00:00:00.000 --> 00:00:01.000
|
||||
NOTE text
|
||||
|
||||
NOTE
|
||||
this is also a real comment that should be ignored
|
||||
this is also a real comment that should be ignored
|
||||
|
||||
00:00:01.000 --> 00:00:02.000
|
||||
NOTE text
|
||||
NOTE text2
|
Загрузка…
Ссылка в новой задаче