Skip to content

Commit fc041f3

Browse files
committed
WIP: compile for .NET 8.0 and 9.0
Signed-off-by: Yves Bastide <[email protected]>
1 parent b7cd8aa commit fc041f3

File tree

7 files changed

+20
-17
lines changed

7 files changed

+20
-17
lines changed

RobotsTxt/Extensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace RobotsTxt
24
{
35
public static class MyExtensions

RobotsTxt/IRobotsParseHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace RobotsTxt
24
{
35
public interface IRobotsParseHandler

RobotsTxt/LongestMatchRobotsMatchStrategy.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace RobotsTxt
1+
using System;
2+
3+
namespace RobotsTxt
24
{
35

46
/// <summary>

RobotsTxt/ParsedRobotsKey.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
using System;
12
using System.Diagnostics;
2-
using System.Text;
33

44
namespace RobotsTxt
55
{
@@ -10,7 +10,7 @@ class ParsedRobotsKey
1010

1111
public enum KeyType
1212
{
13-
// Generic highlevel fields.
13+
// Generic high level fields.
1414
UserAgent,
1515
Sitemap,
1616

RobotsTxt/RobotsMatcher.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
using System.Collections.Generic;
13
using System.Diagnostics;
24
using System.Text;
35

@@ -163,29 +165,24 @@ public void HandleUnknownAction(int lineNum, ReadOnlySpan<byte> action, ReadOnly
163165
{
164166
}
165167

166-
private void InitUserAgentsAndPath(List<string> userAgents, byte[] path)
168+
private void InitUserAgentsAndPath(List<byte[]> userAgents, byte[] path)
167169
{
168-
_userAgents = new List<byte[]>(userAgents.Count);
169-
foreach (var ua in userAgents)
170-
{
171-
_userAgents.Add(Encoding.UTF8.GetBytes(ua));
172-
}
173-
170+
_userAgents = userAgents;
174171
Debug.Assert(path.Length > 0 && path[0] == '/');
175172
_path = path;
176173
}
177174

178175
private bool SeenAnyAgent => _seenGlobalAgent || _seenSpecificAgent;
179176

180-
public bool AllowedByRobots(byte[] robotsBody, List<string> userAgents, string url)
177+
public bool AllowedByRobots(byte[] robotsBody, List<byte[]> userAgents, string url)
181178
{
182179
// The url is not normalized (escaped, percent encoded) here because the user
183180
// is asked to provide it in escaped form already.
184181
var path = GetPathParamsQuery(url);
185182
return PathAllowedByRobots(robotsBody, userAgents, new UTF8Encoding().GetBytes(path));
186183
}
187184

188-
public bool PathAllowedByRobots(byte[] robotsBody, List<string> userAgents, byte[] path)
185+
public bool PathAllowedByRobots(byte[] robotsBody, List<byte[]> userAgents, byte[] path)
189186
{
190187
InitUserAgentsAndPath(userAgents, path);
191188
ParseRobotsTxt(robotsBody, this);
@@ -313,9 +310,9 @@ public void Clear()
313310
byte[]? _path;
314311
private List<byte[]>? _userAgents; // Set by InitUserAgentsAndPath.
315312

316-
public bool OneAgentAllowedByRobots(byte[] robotsContent, string userAgent, string url)
313+
public bool OneAgentAllowedByRobots(byte[] robotsContent, byte[] userAgent, string url)
317314
{
318-
var userAgents = new List<string> { userAgent };
315+
var userAgents = new List<byte[]> { userAgent, };
319316
return AllowedByRobots(robotsContent, userAgents, url);
320317
}
321318

RobotsTxt/RobotsTxt.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<Configurations>Debug;Release</Configurations>

RobotsTxt/RobotsTxtParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System.Text;
1+
using System;
22

33
namespace RobotsTxt
44
{
55
public class RobotsTxtParser
66
{
77
static readonly byte[] UtfBom = { 0xEF, 0xBB, 0xBF };
8-
static readonly byte[] HexDigits = Encoding.ASCII.GetBytes("0123456789ABCDEF");
8+
static readonly byte[] HexDigits = "0123456789ABCDEF"u8.ToArray();
99

1010
public void Parse()
1111
{

0 commit comments

Comments
 (0)