Skip to content

Commit

Permalink
When parsing a line with no key, just skip it instead of throwing (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyah authored Feb 17, 2017
1 parent 187890c commit 0d79c77
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
12 changes: 0 additions & 12 deletions src/IniFileParser.Tests/Unit/Configuration/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ public LiberalTestConfiguration()
name = Marble Zone
";

string iniFileReallyBad =
@"
{no section}
key # = wops!
= value
";
#endregion

[SetUp]
Expand Down Expand Up @@ -107,12 +101,6 @@ public void check_configuration_is_correct()
Assert.That(_parser.Parse(iniFileStr).Configuration, Is.InstanceOf(typeof(LiberalTestConfiguration)));
}

[Test]
public void parser_really_bad_ini_format()
{
Assert.That(_parser.Parse(iniFileReallyBad), Is.Null);
}

[Test]
public void parse_not_so_good_ini_format()
{
Expand Down
5 changes: 4 additions & 1 deletion src/IniFileParser.Tests/Unit/Parser/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ public void allow_skiping_unparsable_lines()
{
string data =
@"win]
key1 = value1";
key1 = value1
= value2";

var parser = new IniDataParser();

Expand Down Expand Up @@ -508,5 +509,7 @@ [W103 0.5' wc]
Assert.That(parsedData.Sections["W101 0.5\" wc"], Is.Not.Empty);
Assert.That(parsedData.Sections["W103 0.5' wc"], Is.Not.Empty);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public string NewLineStr
/// Defaults to <c>true</c>.
/// </remarks>
public bool AllowKeysWithoutSection { get; set; }

/// <summary>
/// If set to <c>false</c> and the <see cref="IniDataParser"/> finds duplicate keys in a
/// section the parser will stop with an error.
Expand Down
3 changes: 3 additions & 0 deletions src/IniFileParser/Parser/IniDataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ protected virtual void ProcessKeyValuePair(string line, IniData currentIniData)
{
// get key and value data
string key = ExtractKey(line);

if (string.IsNullOrEmpty(key) && Configuration.SkipInvalidLines) return;

string value = ExtractValue(line);

// Check if we haven't read any section yet
Expand Down

0 comments on commit 0d79c77

Please sign in to comment.