Salamek / huawei-lte-api-ts

API For huawei LAN/WAN LTE Modems written in TypeScript
GNU Lesser General Public License v3.0
48 stars 19 forks source link

Password with character '@' results to Error: 108006 #20

Closed steinxborg closed 2 years ago

steinxborg commented 2 years ago

Password with character '@' results to Error: 108006: Username and Password wrong

// results to Error: 108006: Username and Password wrong const connection = new huaweiLteApi.Connection('http://admin:@123456789@192.168.8.1/');

// results to Error: 108006: Username and Password wrong const connection = new huaweiLteApi.Connection('http://admin:12345@6789@192.168.8.1/');

steinxborg commented 2 years ago

The python version does not have this bug.

Salamek commented 2 years ago

Looks like JS URL parser is a bit shitty...

https://github.com/Salamek/huawei-lte-api-ts/blob/master/src/Connection.ts#L45-L49


const url = 'http://admin:12345@6789@192.168.8.1/';

const urlInfo = new URL(url);
const username = urlInfo.username;
const password = urlInfo.password;
urlInfo.username = '';
urlInfo.password = '';

console.log(url);

console.log(username);
console.log(password);

console.log(urlInfo.toString());
http://admin:12345@6789@192.168.8.1/
admin
12345%406789
http://192.168.8.1/

And i'm not sure how to correctly solve this one, my googlefu is not returning any sane results...

Salamek commented 2 years ago

@stein-dev ok found out that username and password are using encodeURIComponent, so just decodeURIComponent for username and password should fix this