diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 36a2de9..d9d254a 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -1150,13 +1150,12 @@ sub parse_config { my $cfg = {}; - while ($raw && $raw =~ s/^(.*?)(\n|$)//) { + while ($raw =~ /^\s*(.+?)\s*$/gm) { my $line = $1; - - next if $line =~ m/^\#/; # skip comment lines - next if $line =~ m/^\s*$/; # skip empty lines - if ($line =~ m/^(\S+):\s*(\S+)\s*$/) { + next if $line =~ /^#/; + + if ($line =~ m/^(\S+?):\s*(.*)$/) { my $key = $1; my $value = $2; if ($schema->{properties}->{$key} && diff --git a/src/PVE/SectionConfig.pm b/src/PVE/SectionConfig.pm index 06ebbe7..5fc479e 100644 --- a/src/PVE/SectionConfig.pm +++ b/src/PVE/SectionConfig.pm @@ -231,19 +231,22 @@ sub parse_config { my $ids = {}; my $order = {}; - my $digest = Digest::SHA::sha1_hex(defined($raw) ? $raw : ''); + $raw = '' if !defined($raw); + + my $digest = Digest::SHA::sha1_hex($raw); my $pri = 1; my $lineno = 0; + my @lines = split(/\n/, $raw); + my $nextline = sub { + while (my $line = shift @lines) { + $lineno++; + return $line if $line !~ /^\s*(?:#|$)/; + } + }; - while ($raw && $raw =~ s/^(.*?)(\n|$)//) { - my $line = $1; - $lineno++; - - next if $line =~ m/^\#/; - next if $line =~ m/^\s*$/; - + while (my $line = &$nextline()) { my $errprefix = "file $filename line $lineno"; my ($type, $sectionId, $errmsg, $config) = $class->parse_section_header($line); @@ -266,13 +269,7 @@ sub parse_config { } } - while ($raw && $raw =~ s/^(.*?)(\n|$)//) { - $line = $1; - $lineno++; - - next if $line =~ m/^\#/; - last if $line =~ m/^\s*$/; - + while ($line = &$nextline()) { next if $ignore; # skip $errprefix = "file $filename line $lineno";