Handle empty username case

This commit is contained in:
Ilya Ig. Petrov 2017-11-01 00:19:10 +05:00
parent 8f1ce3b6ea
commit 9b35c413cc
2 changed files with 7 additions and 2 deletions

View File

@ -268,7 +268,7 @@
proxyHostToCredsList[`${hostname}:${port}`] || [];
const tries = proxyHostToCredsList[`${hostname}:${port}`];
tries.push({
username,
username: username || '',
password: password || '',
});

View File

@ -408,6 +408,8 @@ export default function getProxyEditor(theState) {
creds,
hostname,
port,
username,
password,
} = theState.utils.parseProxyScheme(proxyAsString);
const crededAddr = `${creds ? `${creds}@` : ''}${hostname}:${port}`;
@ -417,11 +419,14 @@ export default function getProxyEditor(theState) {
`Неверный тип ${type}. Известные типы: ${knownTypes.join(', ')}.`
);
}
if (!(crededAddr && /^(?:[^@]+@)?[^:]+:\d+$/.test(crededAddr))) {
if (!(crededAddr && /^(?:.+@)?[^:]+:\d+$/.test(crededAddr))) {
return new Error(
`Адрес прокси "${crededAddr || ''}" не соответствует формату "<опц_логин>:<опц_пароль>@<домен_или_IP>:<порт_из_цифр>".`
);
}
if (password && !username) {
return new Error('Вашему пользователю не хватает имени?');
}
const portInt = parseInt(port);
if (portInt < 0 || portInt > 65535) {
return new Error(