mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +00:00
PM-25242 added normalization for android URIs and updated test coverage (#16329)
This commit is contained in:
@@ -20,7 +20,7 @@ const CipherData = [
|
|||||||
password: "Qh6W4Wz55YGFNU",
|
password: "Qh6W4Wz55YGFNU",
|
||||||
uris: [
|
uris: [
|
||||||
Object.assign(new LoginUriView(), {
|
Object.assign(new LoginUriView(), {
|
||||||
uri: "android://N2H9MndUUUt3JuQSWAKexOU9oJLJeHR4nyUGac5E1TXKppkY7xtdRl6l8vKo1hQWCqAEy4gsNLUBIbVxpdmhOP==@com.xyz.example.app.android/",
|
uri: "androidapp://com.xyz.example.app.android",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ import { Importer } from "./importer";
|
|||||||
export class ChromeCsvImporter extends BaseImporter implements Importer {
|
export class ChromeCsvImporter extends BaseImporter implements Importer {
|
||||||
private androidPatternRegex = new RegExp("^android:\\/\\/.*(?<=@)(.*)(?=\\/)");
|
private androidPatternRegex = new RegExp("^android:\\/\\/.*(?<=@)(.*)(?=\\/)");
|
||||||
|
|
||||||
|
private normalizeAndroidUrl(url: string): string {
|
||||||
|
const match = url?.match(this.androidPatternRegex);
|
||||||
|
return match ? `androidapp://${match[1]}` : url;
|
||||||
|
}
|
||||||
|
|
||||||
parse(data: string): Promise<ImportResult> {
|
parse(data: string): Promise<ImportResult> {
|
||||||
const result = new ImportResult();
|
const result = new ImportResult();
|
||||||
const results = this.parseCsv(data, true);
|
const results = this.parseCsv(data, true);
|
||||||
@@ -16,6 +21,8 @@ export class ChromeCsvImporter extends BaseImporter implements Importer {
|
|||||||
|
|
||||||
results.forEach((value) => {
|
results.forEach((value) => {
|
||||||
const cipher = this.initLoginCipher();
|
const cipher = this.initLoginCipher();
|
||||||
|
const normalizedUri = this.normalizeAndroidUrl(value.url);
|
||||||
|
|
||||||
let name = value.name;
|
let name = value.name;
|
||||||
if (!name && this.androidPatternRegex.test(value.url)) {
|
if (!name && this.androidPatternRegex.test(value.url)) {
|
||||||
name = value.url.match(this.androidPatternRegex)[1];
|
name = value.url.match(this.androidPatternRegex)[1];
|
||||||
@@ -23,7 +30,7 @@ export class ChromeCsvImporter extends BaseImporter implements Importer {
|
|||||||
cipher.name = this.getValueOrDefault(name, "--");
|
cipher.name = this.getValueOrDefault(name, "--");
|
||||||
cipher.login.username = this.getValueOrDefault(value.username);
|
cipher.login.username = this.getValueOrDefault(value.username);
|
||||||
cipher.login.password = this.getValueOrDefault(value.password);
|
cipher.login.password = this.getValueOrDefault(value.password);
|
||||||
cipher.login.uris = this.makeUriArray(value.url);
|
cipher.login.uris = this.makeUriArray(normalizedUri);
|
||||||
cipher.notes = this.getValueOrDefault(value.note);
|
cipher.notes = this.getValueOrDefault(value.note);
|
||||||
this.cleanupCipher(cipher);
|
this.cleanupCipher(cipher);
|
||||||
result.ciphers.push(cipher);
|
result.ciphers.push(cipher);
|
||||||
|
|||||||
Reference in New Issue
Block a user