File tree Expand file tree Collapse file tree 2 files changed +19
-10
lines changed Expand file tree Collapse file tree 2 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -53,16 +53,25 @@ class Keychain {
53
53
try {
54
54
const csvData = papaparse . parse ( fileContents , {
55
55
header : true ,
56
- skipEmptyLines :true ,
57
- transformHeader ( header ) {
56
+ skipEmptyLines : true ,
57
+ transformHeader ( header ) {
58
58
return header . toLowerCase ( ) . trim ( ) . replace ( / [ " ' ] / g, '' )
59
- } ,
59
+ }
60
60
} )
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 ( / ^ h t t p s ? : \/ \/ / g)
64
+ const domainWithProtocol = includesProtocol ? credential . url : `https://${ credential . url } `
65
+
66
+ return {
67
+ domain : new URL ( domainWithProtocol ) . hostname . replace ( / ^ w w w \. / g, '' ) ,
68
+ username : credential . username ,
69
+ password : credential . password
70
+ }
71
+ } catch {
72
+ return null
73
+ }
74
+ } ) . filter ( credential => credential !== null )
66
75
67
76
if ( credentialsToImport . length === 0 ) return [ ]
68
77
Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ const passwordViewer = {
129
129
throw new Error ( 'unsupported password manager' )
130
130
}
131
131
132
- const credentials = await manager . getAllCredentials ( ) ;
132
+ const credentials = await manager . getAllCredentials ( )
133
133
const shouldShowConsent = credentials . length > 0
134
134
135
135
if ( shouldShowConsent ) {
@@ -179,7 +179,7 @@ const passwordViewer = {
179
179
if ( credentials . length === 0 ) return
180
180
181
181
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' )
183
183
const blob = new Blob ( [ csvData ] , { type : 'text/csv' } )
184
184
const url = URL . createObjectURL ( blob )
185
185
const anchor = document . createElement ( 'a' )
You can’t perform that action at this time.
0 commit comments