Bug 1307710 - part3: fix ProcessingInstruction node for testcase. r=rillian
MozReview-Commit-ID: 9Wc98cOVjHD
--- a/dom/media/webvtt/vtt.jsm
+++ b/dom/media/webvtt/vtt.jsm
@@ -348,16 +348,41 @@ Cu.import('resource://gre/modules/Servic
element.localName = tagName;
var name = TAG_ANNOTATION[type];
if (name) {
element[name] = annotation ? annotation.trim() : "";
}
return element;
}
+ // https://w3c.github.io/webvtt/#webvtt-timestamp-object
+ // Return hhhhh:mm:ss.fff
+ function normalizedTimeStamp(secondsWithFrag) {
+ var totalsec = parseInt(secondsWithFrag, 10);
+ var hours = Math.floor(totalsec / 3600);
+ var minutes = Math.floor(totalsec % 3600 / 60);
+ var seconds = Math.floor(totalsec % 60);
+ if (hours < 10) {
+ hours = "0" + hours;
+ }
+ if (minutes < 10) {
+ minutes = "0" + minutes;
+ }
+ if (seconds < 10) {
+ seconds = "0" + seconds;
+ }
+ var f = secondsWithFrag.toString().split(".");
+ if (f[1]) {
+ f = f[1].slice(0, 3).padEnd(3, "0");
+ } else {
+ f = "000";
+ }
+ return hours + ':' + minutes + ':' + seconds + '.' + f;
+ }
+
var root;
if (bReturnFrag) {
root = window.document.createDocumentFragment();
} else {
root = window.document.createElement("div");
}
var current = root,
t,
@@ -374,17 +399,17 @@ Cu.import('resource://gre/modules/Servic
}
// Otherwise just ignore the end tag.
continue;
}
var ts = collectTimeStamp(t.substr(1, t.length - 2));
var node;
if (ts) {
// Timestamps are lead nodes as well.
- node = window.document.createProcessingInstruction("timestamp", ts);
+ node = window.document.createProcessingInstruction("timestamp", normalizedTimeStamp(ts));
current.appendChild(node);
continue;
}
var m = t.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/);
// If we can't parse the tag, skip to the next tag.
if (!m) {
continue;
}