Skip to content

Commit d413fc0

Browse files
Merge branch 'feature/Sprache_cookie_header_parsing' into develop
2 parents 3ae1ae7 + fd553a3 commit d413fc0

24 files changed

+703
-117
lines changed

NScrape.Test/Cookies/SetCookieHeaderGrammarTests.cs

Lines changed: 496 additions & 0 deletions
Large diffs are not rendered by default.

NScrape.Test/HtmlFormDefinitionTests.cs renamed to NScrape.Test/Forms/HtmlFormDefinitionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.Linq;
2-
using Xunit;
32
using NScrape.Forms;
3+
using Xunit;
44

5-
namespace NScrape.Test {
5+
namespace NScrape.Test.Forms {
66
public class HtmlFormDefinitionTests {
77
[Fact]
88
public void TestSingleFormTextsAndDropdown() {

NScrape.Test/HtmlFormTests.cs renamed to NScrape.Test/Forms/HtmlFormTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using Xunit;
54
using NScrape.Forms;
5+
using Xunit;
66

7-
namespace NScrape.Test {
7+
namespace NScrape.Test.Forms {
88
public class HtmlFormTests {
99
private class TestScraper : Scraper {
1010
public TestScraper( string html ) : base( html ) {

NScrape.Test/NScrape.Test.csproj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,21 @@
3232
<ErrorReport>prompt</ErrorReport>
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
35+
<PropertyGroup>
36+
<SignAssembly>true</SignAssembly>
37+
</PropertyGroup>
38+
<PropertyGroup>
39+
<AssemblyOriginatorKeyFile>nscrape.snk</AssemblyOriginatorKeyFile>
40+
</PropertyGroup>
3541
<ItemGroup>
3642
<Reference Include="HtmlAgilityPack, Version=1.4.9.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
3743
<SpecificVersion>False</SpecificVersion>
3844
<HintPath>..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll</HintPath>
3945
</Reference>
46+
<Reference Include="Sprache, Version=2.0.0.52, Culture=neutral, processorArchitecture=MSIL">
47+
<SpecificVersion>False</SpecificVersion>
48+
<HintPath>..\packagesSigned\Sprache.2.0.0.52\lib\portable-net4+netcore45+win8+wp8+sl5+MonoAndroid+Xamarin.iOS10+MonoTouch\Sprache.dll</HintPath>
49+
</Reference>
4050
<Reference Include="System" />
4151
<Reference Include="System.Core" />
4252
<Reference Include="System.Drawing" />
@@ -50,12 +60,13 @@
5060
</Reference>
5161
</ItemGroup>
5262
<ItemGroup>
63+
<Compile Include="Cookies\SetCookieHeaderGrammarTests.cs" />
5364
<Compile Include="NScrapeUtilityParseSetCookieHeaderTests.cs" />
5465
<Compile Include="NScrapeExtensionTests.cs" />
5566
<Compile Include="WebResponseTests.cs" />
5667
<Compile Include="NScrapeUtilityTryParseHttpDateTests.cs" />
57-
<Compile Include="HtmlFormTests.cs" />
58-
<Compile Include="HtmlFormDefinitionTests.cs" />
68+
<Compile Include="Forms\HtmlFormTests.cs" />
69+
<Compile Include="Forms\HtmlFormDefinitionTests.cs" />
5970
<Compile Include="Properties\AssemblyInfo.cs" />
6071
<Compile Include="Properties\Resources.Designer.cs">
6172
<AutoGen>True</AutoGen>
@@ -64,6 +75,7 @@
6475
</Compile>
6576
</ItemGroup>
6677
<ItemGroup>
78+
<None Include="nscrape.snk" />
6779
<None Include="packages.config" />
6880
</ItemGroup>
6981
<ItemGroup>

NScrape.Test/NScrapeUtilityParseSetCookieHeaderTests.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class NScrapeUtilityParseSetCookieHeaderTests {
1414
private const string CookieFrederik = "ADCDownloadAuth=[long token];Version=1;Comment=;Domain=apple.com;Path=/;Max-Age=108000;HttpOnly;Expires=Tue, 03 May 2016 13:30:57 GMT";
1515
private const string CookieOddExpiresDate1 = "__cfduid=d9de9c2173f6f46cc6a9457aada153ace1467497253; expires=Sun 02-Jul-17 22:07:33 GMT; path=/; domain=.typicode.com; HttpOnly";
1616
private const string CookieOddExpiresDate2 = "__cfduid=d9de9c2173f6f46cc6a9457aada153ace1467497253; expires=Sun, 02-Jul-17 22:07:33 GMT; path=/; domain=.typicode.com; HttpOnly";
17-
private const string CookieOddExpiresDate3 = "__cfduid=d9de9c2173f6f46cc6a9457aada153ace1467497253; expires=Sun, 02-Jul-17, 22:07:33, GMT; path=/; domain=.typicode.com; HttpOnly";
1817
private const string CookieOddExpiresDateAnsiCasctime = "__cfduid=d9de9c2173f6f46cc6a9457aada153ace1467497253; expires=Sun Jul 2 22:07:33 2017; path=/; domain=.typicode.com; HttpOnly";
1918
private const string CookieOddExpiresDateRfc850 = "__cfduid=d9de9c2173f6f46cc6a9457aada153ace1467497253; expires=Sunday, 02-Jul-17 22:07:33 GMT; path=/; domain=.typicode.com; HttpOnly";
2019

@@ -137,12 +136,7 @@ public void OddExpiresDateTests() {
137136

138137
[Fact]
139138
public void OddExpiresDateFailingTests() {
140-
// BUG: Tests below fail; code assumes expires must have one and only 1 comma; better parsing needed...regex?
141-
var cookies = NScrapeUtility.ParseSetCookieHeader( CookieOddExpiresDate3, DefaultDomain ).ToList();
142-
Assert.Equal( 1, cookies.Count );
143-
CookieOddExpiresDateTest( cookies[0] );
144-
145-
cookies = NScrapeUtility.ParseSetCookieHeader( string.Join( ",", CookieOddExpiresDate1, CookieOddExpiresDate2 ), DefaultDomain ).ToList();
139+
var cookies = NScrapeUtility.ParseSetCookieHeader( string.Join( ",", CookieOddExpiresDate1, CookieOddExpiresDate2 ), DefaultDomain ).ToList();
146140
Assert.Equal( 2, cookies.Count );
147141
CookieOddExpiresDateTest( cookies[0] );
148142
CookieOddExpiresDateTest( cookies[1] );

NScrape.Test/WebResponseTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void ImageWebResponseTest() {
219219
public void BinaryWebResponseTest() {
220220
var webClient = new WebClient();
221221

222-
var uri = new Uri( "https://download-cdn.getsync.com/stable/windows64/BitTorrent-Sync_x64.exe" );
222+
var uri = new Uri( "https://download-cdn.getsync.com/stable/windows64/Resilio-Sync_x64.exe" );
223223

224224
using ( var response = webClient.SendRequest( uri ) ) {
225225
Assert.NotNull( response );
@@ -249,7 +249,7 @@ public void BinaryWebResponseTest() {
249249
public void BinaryWebResponseDataPropertyBackwardsCompatibilityTest() {
250250
var webClient = new WebClient();
251251

252-
var uri = new Uri( "https://download-cdn.getsync.com/stable/windows64/BitTorrent-Sync_x64.exe" );
252+
var uri = new Uri( "https://download-cdn.getsync.com/stable/windows64/Resilio-Sync_x64.exe" );
253253

254254
using ( var response = webClient.SendRequest( uri ) ) {
255255
Assert.NotNull( response );

NScrape.Test/nscrape.snk

596 Bytes
Binary file not shown.

NScrape.Test/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="Brutal.Dev.StrongNameSigner" version="1.8.0" targetFramework="net45" />
34
<package id="xunit" version="1.9.2" targetFramework="net45" />
45
</packages>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NScrape.Cookies {
2+
internal class CookieNameValuePair {
3+
4+
public CookieNameValuePair( string name, string value = "" ) {
5+
Name = name;
6+
Value = value;
7+
}
8+
9+
public string Name { get; }
10+
public string Value { get; }
11+
12+
public override string ToString() {
13+
return $"{Name}={Value}";
14+
}
15+
}
16+
}

NScrape/Cookies/ParsedCookie.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
3+
namespace NScrape.Cookies {
4+
internal class ParsedCookie {
5+
public ParsedCookie( CookieNameValuePair cookiePair, IEnumerable<CookieNameValuePair> attributePairs ) {
6+
CookiePair = cookiePair;
7+
AttributePairs = attributePairs;
8+
}
9+
10+
public CookieNameValuePair CookiePair { get; set; }
11+
12+
public IEnumerable<CookieNameValuePair> AttributePairs { get; private set; }
13+
}
14+
}

0 commit comments

Comments
 (0)