@@ -83,10 +83,27 @@ func (store *Store) LoadEncryptedFile(in []byte) (sops.Tree, error) {
8383// LoadPlainFile returns the contents of a plaintext file loaded onto a
8484// sops runtime object
8585func (store * Store ) LoadPlainFile (in []byte ) (sops.TreeBranches , error ) {
86+ lines := bytes .Split (in , []byte ("\n " ))
87+
88+ // Detect the dialect from the first sops_* line: leading '"' means
89+ // quoted, otherwise unquoted.
90+ quote := store .config .Quote
91+ for _ , line := range lines {
92+ if ! bytes .HasPrefix (line , []byte (SopsPrefix )) {
93+ continue
94+ }
95+ _ , raw , ok := bytes .Cut (line , []byte ("=" ))
96+ if ! ok {
97+ continue
98+ }
99+ quote = bytes .HasPrefix (raw , []byte (`"` ))
100+ break
101+ }
102+
86103 var branches sops.TreeBranches
87104 var branch sops.TreeBranch
88105
89- for _ , line := range bytes . Split ( in , [] byte ( " \n " )) {
106+ for _ , line := range lines {
90107 if len (line ) == 0 {
91108 continue
92109 }
@@ -101,7 +118,7 @@ func (store *Store) LoadPlainFile(in []byte) (sops.TreeBranches, error) {
101118 return nil , fmt .Errorf ("invalid dotenv input line: %s" , line )
102119 }
103120 var value string
104- if store . config . Quote {
121+ if quote {
105122 var err error
106123 value , err = strconv .Unquote (string (line [pos + 1 :]))
107124 if err != nil {
0 commit comments