Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated String.prototype.substr() #736

Merged
merged 1 commit into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions js/app/directives/otp.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}

for (i = 0; i + 4 <= bits.length; i += 4) {
var chunk = bits.substr(i, 4);
var chunk = bits.slice(i, i + 4);
hex = hex + parseInt(chunk, 2).toString(16);
}
return hex.length % 2 ? hex + "0" : hex;
Expand Down Expand Up @@ -91,8 +91,8 @@
var hmacObj = new jsSHA(time, 'HEX');
var hmac = hmacObj.getHMAC(key, 'HEX', 'SHA-1', "HEX");
var offset = hex2dec(hmac.substring(hmac.length - 1));
var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + '';
otp = (otp).substr(otp.length - 6, 6);
var otp = (hex2dec(hmac.slice(offset * 2, offset * 2 + 8)) & hex2dec('7fffffff')) + '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

It could be a good idea to move the offset * 2 into a helper temporary variable to avoid recalculating it, but it's not a big deal on this instance.

otp = (otp).slice(-6);
scope.otp = otp;

};
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/js/mocks/OC.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ if (typeof oc_webroot === "undefined") {
oc_webroot = location.pathname;
var pos = oc_webroot.indexOf('/index.php/');
if (pos !== -1) {
oc_webroot = oc_webroot.substr(0, pos);
oc_webroot = oc_webroot.slice(0, pos);
}
else {
oc_webroot = oc_webroot.substr(0, oc_webroot.lastIndexOf('/'));
oc_webroot = oc_webroot.substring(0, oc_webroot.lastIndexOf('/'));
}
}
if (typeof console === "undefined" || typeof console.log === "undefined") {
Expand Down Expand Up @@ -498,7 +498,7 @@ var OC={
}
pos = queryString.indexOf('?');
if (pos >= 0){
queryString = queryString.substr(pos + 1);
queryString = queryString.slice(pos + 1);
}
parts = queryString.replace(/\+/g, '%20').split('&');
for (var i = 0; i < parts.length; i++){
Expand All @@ -507,8 +507,8 @@ var OC={
pos = part.indexOf('=');
if (pos >= 0) {
components = [
part.substr(0, pos),
part.substr(pos + 1)
part.slice(0, pos),
part.slice(pos + 1)
];
}
else {
Expand Down Expand Up @@ -1432,8 +1432,8 @@ function humanFileSize(size, skipSmallSizes) {
if(order < 2){
relativeSize = parseFloat(relativeSize).toFixed(0);
}
else if(relativeSize.substr(relativeSize.length-2,2)==='.0'){
relativeSize=relativeSize.substr(0,relativeSize.length-2);
else if(relativeSize.slice(-2)==='.0'){
relativeSize=relativeSize.slice(0,-2);
}
return relativeSize + ' ' + readableFormat;
}
Expand Down Expand Up @@ -1780,11 +1780,11 @@ OC.Util.History = {
var hash = window.location.hash,
pos = hash.indexOf('?');
if (pos >= 0) {
return hash.substr(pos + 1);
return hash.slice(pos + 1);
}
if (hash.length) {
// remove hash sign
return hash.substr(1);
return hash.slice(1);
}
return '';
},
Expand Down