Skip to content

Commit 5503c45

Browse files
committed
♻️ More API changes
* extract `PathAllowedByRobots` * make `MaybeEscapePattern` public Signed-off-by: Yves Bastide <[email protected]>
1 parent ba823c6 commit 5503c45

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

RobotsTxt/RobotsMatcher.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,16 @@ public void HandleUnknownAction(int lineNum, ReadOnlySpan<byte> action, ReadOnly
163163
{
164164
}
165165

166-
private void InitUserAgentsAndPath(List<string> userAgents, string path)
166+
private void InitUserAgentsAndPath(List<string> userAgents, byte[] path)
167167
{
168168
_userAgents = new List<byte[]>(userAgents.Count);
169169
foreach (var ua in userAgents)
170170
{
171171
_userAgents.Add(Encoding.UTF8.GetBytes(ua));
172172
}
173173

174-
Debug.Assert(path.StartsWith("/"));
175-
_path = Encoding.UTF8.GetBytes(path);
174+
Debug.Assert(path.Length > 0 && path[0] == '/');
175+
_path = path;
176176
}
177177

178178
private bool SeenAnyAgent => _seenGlobalAgent || _seenSpecificAgent;
@@ -182,6 +182,11 @@ public bool AllowedByRobots(byte[] robotsBody, List<string> userAgents, string u
182182
// The url is not normalized (escaped, percent encoded) here because the user
183183
// is asked to provide it in escaped form already.
184184
var path = GetPathParamsQuery(url);
185+
return PathAllowedByRobots(robotsBody, userAgents, new UTF8Encoding().GetBytes(path));
186+
}
187+
188+
public bool PathAllowedByRobots(byte[] robotsBody, List<string> userAgents, byte[] path)
189+
{
185190
InitUserAgentsAndPath(userAgents, path);
186191
ParseRobotsTxt(robotsBody, this);
187192
return !Disallow();

RobotsTxt/RobotsTxtParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private void EmitKeyValueToHandler(int currentLine, ParsedRobotsKey key, ReadOnl
119119
}
120120
}
121121

122-
internal static ReadOnlySpan<byte> MaybeEscapePattern(ReadOnlySpan<byte> src)
122+
public static ReadOnlySpan<byte> MaybeEscapePattern(ReadOnlySpan<byte> src)
123123
{
124124
int numToEscape = 0;
125125
bool needCapitalize = false;

0 commit comments

Comments
 (0)