2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

fix: replace deprecated unescape() with modern UTF-8 encoding (#7378)

- Replace deprecated unescape(encodeURIComponent()) pattern with a
  regex-based encodeUTF8() helper function in resolveConfig.js
- Fix incorrect JSDoc comment for isFileList in utils.js
  (said 'File' instead of 'FileList')

The new encodeUTF8 function produces identical output to the deprecated
pattern, verified against existing basicAuth.spec.js test expectations.

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Karan Mangtani
2026-04-28 19:54:48 +05:30
committed by GitHub
parent cd0d44825f
commit 66337fc6fc
2 changed files with 16 additions and 9 deletions
+15 -8
View File
@@ -7,6 +7,19 @@ import mergeConfig from '../core/mergeConfig.js';
import AxiosHeaders from '../core/AxiosHeaders.js';
import buildURL from './buildURL.js';
/**
* Encode a UTF-8 string to a Latin-1 byte string for use with btoa().
* This is a modern replacement for the deprecated unescape(encodeURIComponent(str)) pattern.
*
* @param {string} str The string to encode
*
* @returns {string} UTF-8 bytes as a Latin-1 string
*/
const encodeUTF8 = (str) => encodeURIComponent(str).replace(
/%([0-9A-F]{2})/gi,
(_, hex) => String.fromCharCode(parseInt(hex, 16))
);
export default (config) => {
const newConfig = mergeConfig({}, config);
@@ -34,14 +47,8 @@ export default (config) => {
// HTTP basic authentication
if (auth) {
headers.set(
'Authorization',
'Basic ' +
btoa(
(auth.username || '') +
':' +
(auth.password ? unescape(encodeURIComponent(auth.password)) : '')
)
headers.set('Authorization', 'Basic ' +
btoa((auth.username || '') + ':' + (auth.password ? encodeUTF8(auth.password) : ''))
);
}
+1 -1
View File
@@ -225,7 +225,7 @@ const isBlob = kindOfTest('Blob');
*
* @param {*} val The value to test
*
* @returns {boolean} True if value is a File, otherwise false
* @returns {boolean} True if value is a FileList, otherwise false
*/
const isFileList = kindOfTest('FileList');