1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Replace String.prototype.substr() occurrences with String.prototype.substring()

As outlined in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr, which refers to the ECMA-262 specification, using the `substr` function is advised against.

Hence this PR, which replaces all remaining `substr` occurrences with `substring` instead. Please refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr#Syntax respectively https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring#Syntax for the differences between the two functions.

Note that in most cases in the code-base there's only one argument passed to `substr`, and those require no other changes except replacing "substr" with "substring". For the other cases, the `substr(start, length)` calls are changed to `substring(start, start + length)` instead.
This commit is contained in:
Jonas Jenwald 2018-09-28 11:41:07 +02:00
parent 54d6c2436c
commit 842e9206c0
15 changed files with 24 additions and 23 deletions

View file

@ -46,14 +46,15 @@ calculateMD5(file, (err, md5) => {
}
let contents = fs.readFileSync(gitIgnore, 'utf8').split('\n');
let randomLine = getRandomArbitrary(10, contents.length - 2);
contents.splice(randomLine, 0, '!' + file.substr(file.lastIndexOf('/') + 1));
contents.splice(randomLine, 0,
'!' + file.substring(file.lastIndexOf('/') + 1));
fs.writeFileSync('test/pdfs/.gitignore', contents.join('\n'));
contents = fs.readFileSync(testManifest, 'utf8');
let pdf = file.substring(file.lastIndexOf('/') + 1, file.length - 4);
let randomPoint = getRandomArbitrary(100, contents.length - 20);
let bracket = contents.indexOf('},\n', randomPoint);
let out = contents.substr(0, bracket) +
let out = contents.substring(0, bracket) +
'},\n' +
` { "id": "${pdf}",\n` +
` "file": "pdfs/${pdf}.pdf",\n` +
@ -61,7 +62,7 @@ calculateMD5(file, (err, md5) => {
' "rounds": 1,\n' +
' "type": "eq"\n' +
' ' +
contents.substr(bracket);
contents.substring(bracket);
fs.writeFileSync('test/test_manifest.json', out);
execSync(`git add ${testManifest} ${gitIgnore}`);
execSync(`git add ${file}`);

View file

@ -52,7 +52,7 @@ window.onload = function() {
function hashParameters() {
var result = { };
var params = window.location.hash.substr(1).split(/[&;]/);
var params = window.location.hash.substring(1).split(/[&;]/);
for (var i = 0; i < params.length; i++) {
var parts = params[i].split("=");
result[parts[0]] = unescape(unescape(parts[1]));

View file

@ -52,7 +52,7 @@ describe('CFFParser', function() {
'f78e14';
var fontArr = [];
for (var i = 0, ii = exampleFont.length; i < ii; i += 2) {
var hex = exampleFont.substr(i, 2);
var hex = exampleFont.substring(i, i + 2);
fontArr.push(parseInt(hex, 16));
}
fontData = new Stream(fontArr);