A couple of small improvements of the Metadata._repair
method
- Remove the "capturing group" in the regular expression that removes leading "junk" from the raw metadata, since it's not necessary here (it's simply a case of too much copy-pasting in a prior patch). According to [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#Groups_and_ranges) you want to, for performance reasons, avoid "capturing groups" unless actually needed. - Add inline comments to document a bunch of magic values in the code.
This commit is contained in:
parent
993a1d7825
commit
3f1568b51a
@ -37,7 +37,7 @@ class Metadata {
|
|||||||
_repair(data) {
|
_repair(data) {
|
||||||
// Start by removing any "junk" before the first tag (see issue 10395).
|
// Start by removing any "junk" before the first tag (see issue 10395).
|
||||||
return data
|
return data
|
||||||
.replace(/^([^<]+)/, "")
|
.replace(/^[^<]+/, "")
|
||||||
.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
|
.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
|
||||||
const bytes = codes
|
const bytes = codes
|
||||||
.replace(/\\([0-3])([0-7])([0-7])/g, function(code, d1, d2, d3) {
|
.replace(/\\([0-3])([0-7])([0-7])/g, function(code, d1, d2, d3) {
|
||||||
@ -63,11 +63,11 @@ class Metadata {
|
|||||||
for (let i = 0, ii = bytes.length; i < ii; i += 2) {
|
for (let i = 0, ii = bytes.length; i < ii; i += 2) {
|
||||||
const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
|
const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
|
||||||
if (
|
if (
|
||||||
code >= 32 &&
|
code >= /* Space = */ 32 &&
|
||||||
code < 127 &&
|
code < /* Delete = */ 127 &&
|
||||||
code !== 60 &&
|
code !== /* '<' = */ 60 &&
|
||||||
code !== 62 &&
|
code !== /* '>' = */ 62 &&
|
||||||
code !== 38
|
code !== /* '&' = */ 38
|
||||||
) {
|
) {
|
||||||
chars += String.fromCharCode(code);
|
chars += String.fromCharCode(code);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user