Hello,

I decided to migrate my LastPass vault to pass, and I ran into some trouble 
with the import script. But they were easy fixes, and I hope they will be 
useful to someone else.

If there are any problems with the patch, please let me know.

-- 
--Lyle
>From db35a3eff8574241dbcbd2827be584285d44358f Mon Sep 17 00:00:00 2001
From: Lyle Mantooth <[email protected]>
Date: Mon, 7 Oct 2019 11:19:10 -0400
Subject: [PATCH] Use proper CSV parsing. Avoid errors from malformed data.

---
 contrib/importers/lastpass2pass.rb | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/contrib/importers/lastpass2pass.rb b/contrib/importers/lastpass2pass.rb
index bf46c8c..5965889 100755
--- a/contrib/importers/lastpass2pass.rb
+++ b/contrib/importers/lastpass2pass.rb
@@ -62,8 +62,8 @@ class Record
     s << "#{@password}\n---\n"
     s << "#{@grouping} / " unless @grouping.empty?
     s << "#{@name}\n"
-    s << "username: #{@username}\n" unless @username.empty?
-    s << "password: #{@password}\n" unless @password.empty?
+    s << "username: #{@username}\n" unless @username.nil? or @username.empty?
+    s << "password: #{@password}\n" unless @password.nil? or @password.empty?
     s << "url: #{@url}\n" unless @url == "http://sn";
     s << "#{@extra}\n" unless @extra.nil?
     return s
@@ -71,29 +71,21 @@ class Record
 end
 
 # Extract individual records
+require 'csv'
 entries = []
 entry = ""
 begin
-  file = File.open(filename)
-  file.each do |line|
-    if line =~ /^(http|ftp|ssh)/
-      entries.push(entry)
-      entry = ""
-    end
-    entry += line
-  end
-  entries.push(entry)
-  entries.shift
+  entries = CSV.read(filename, { headers: true })
   puts "#{entries.length} records found!"
 rescue
-  puts "Couldn't find #{filename}!"
+  puts "Couldn't find #{filename}! ", $!, "\n"
   exit 1
 end
 
 # Parse records and create Record objects
 records = []
 entries.each do |e|
-  args = e.split(",")
+  args = e.fields()
   url = args.shift
   username = args.shift
   password = args.shift
-- 
2.20.1

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Password-Store mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to