Skip to content

Commit

Permalink
Improved TOTP URL parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jul 29, 2024
1 parent 0bcdad2 commit 59f7ef8
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions interface/utils/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,19 @@ export const textConverter = (text: string, sortNumber: number): LibImportFile =
* @return {string} string
*/
export const totpImageConverter = (data: string): string => {
// get url
let url = data.replaceAll(/\s/g, "")
url = url.slice(15)
const uri = new URL(data)

// get name
const nameIndex = url.match(/[?]/)
const name = url.slice(0, nameIndex.index)
url = url.slice(name.length + 1)
const name = uri.pathname.slice(1)

// get secret
const secretIndex = url.match(/[&]/)
const secret = url.slice(7, secretIndex.index)
url = url.slice(secret.length + 14 + 1)
const secret = uri.searchParams.get("secret")

// get issuer
const issuerIndex = url.match(/[&]/)
let issuer = issuerIndex ? url.slice(0, issuerIndex.index) : url
let issuer = uri.searchParams.get("issuer")

// check if issuer is empty
if (issuer === "") {
if (issuer === "" || issuer === null) {
issuer = name
}

Expand Down

0 comments on commit 59f7ef8

Please sign in to comment.