Skip to content

Commit 7d1797c

Browse files
committed
fix: import/export credentials protocol/subdomain not compatible
1 parent 67d80f2 commit 7d1797c

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

js/passwordManager/keychain.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,25 @@ class Keychain {
5353
try {
5454
const csvData = papaparse.parse(fileContents, {
5555
header: true,
56-
skipEmptyLines:true,
57-
transformHeader(header) {
56+
skipEmptyLines: true,
57+
transformHeader (header) {
5858
return header.toLowerCase().trim().replace(/["']/g, '')
59-
},
59+
}
6060
})
61-
const credentialsToImport = csvData.data.map((credential) => ({
62-
domain: credential.url,
63-
username: credential.username,
64-
password: credential.password
65-
}))
61+
const credentialsToImport = csvData.data.map((credential) => {
62+
try {
63+
const includesProtocol = credential.url.match(/^https?:\/\//g)
64+
const domainWithProtocol = includesProtocol ? credential.url : `https://${credential.url}`
65+
66+
return {
67+
domain: new URL(domainWithProtocol).hostname.replace(/^www\./g, ''),
68+
username: credential.username,
69+
password: credential.password
70+
}
71+
} catch {
72+
return null
73+
}
74+
}).filter(credential => credential !== null)
6675

6776
if (credentialsToImport.length === 0) return []
6877

js/passwordManager/passwordViewer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const passwordViewer = {
129129
throw new Error('unsupported password manager')
130130
}
131131

132-
const credentials = await manager.getAllCredentials();
132+
const credentials = await manager.getAllCredentials()
133133
const shouldShowConsent = credentials.length > 0
134134

135135
if (shouldShowConsent) {
@@ -179,7 +179,7 @@ const passwordViewer = {
179179
if (credentials.length === 0) return
180180

181181
const header = 'url,username,password\n'
182-
const csvData = header + credentials.map(credential => `${credential.domain},${credential.username},${credential.password}`).join('\n')
182+
const csvData = header + credentials.map(credential => `https://${credential.domain},${credential.username},${credential.password}`).join('\n')
183183
const blob = new Blob([csvData], { type: 'text/csv' })
184184
const url = URL.createObjectURL(blob)
185185
const anchor = document.createElement('a')

0 commit comments

Comments
 (0)