File tree 3 files changed +78
-8
lines changed
3 files changed +78
-8
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,11 @@ export function parseRobotsTxt(s: string): ParsedRobotsTxt {
34
34
if ( sepIndex === - 1 )
35
35
continue
36
36
// get the rule, pop before the first :
37
- const rule = line . substring ( 0 , sepIndex ) . trim ( )
37
+ const rule = line . substring ( 0 , sepIndex ) . trim ( ) . toLowerCase ( )
38
38
const val = line . substring ( sepIndex + 1 ) . trim ( )
39
39
40
40
switch ( rule ) {
41
- case 'User -agent' :
41
+ case 'user -agent' :
42
42
if ( createNewGroup ) {
43
43
groups . push ( {
44
44
...currentGroup ,
@@ -53,21 +53,21 @@ export function parseRobotsTxt(s: string): ParsedRobotsTxt {
53
53
}
54
54
currentGroup . userAgent . push ( val )
55
55
break
56
- case 'Allow ' :
56
+ case 'allow ' :
57
57
currentGroup . allow . push ( val )
58
58
createNewGroup = true
59
59
break
60
- case 'Disallow ' :
60
+ case 'disallow ' :
61
61
currentGroup . disallow . push ( val )
62
62
createNewGroup = true
63
63
break
64
- case 'Sitemap ' :
64
+ case 'sitemap ' :
65
65
sitemaps . push ( val )
66
66
break
67
- case 'Host ' :
67
+ case 'host ' :
68
68
currentGroup . host = val
69
69
break
70
- case 'Clean -param' :
70
+ case 'clean -param' :
71
71
if ( currentGroup . userAgent . includes ( 'Yandex' ) ) {
72
72
currentGroup . cleanParam = currentGroup . cleanParam || [ ]
73
73
currentGroup . cleanParam . push ( val )
Original file line number Diff line number Diff line change
1
+ # see rfc 9309
2
+ user-agent: ExampleBot
3
+ disallow: /foo
4
+ allow: /bar
5
+
6
+ user-agent: examplebot
7
+ disallow: /baz
8
+ allow: /boo
9
+
10
+ user-agent:
11
+ disallow: /invalid
12
+
13
+ user-agent: *
14
+ disallow: /star
Original file line number Diff line number Diff line change @@ -245,7 +245,7 @@ describe('robotsTxtParser', () => {
245
245
} )
246
246
247
247
it ( 'yandex' , async ( ) => {
248
- // read fixture yoastRobots .txt
248
+ // read fixture yandex .txt
249
249
const robotsTxt = await fsp . readFile ( './test/fixtures/yandex.txt' , { encoding : 'utf-8' } )
250
250
expect ( parseRobotsTxt ( robotsTxt ) ) . toMatchInlineSnapshot ( `
251
251
{
@@ -281,4 +281,60 @@ describe('robotsTxtParser', () => {
281
281
}
282
282
` )
283
283
} )
284
+
285
+ it ( 'case-insensitive startgroupline' , async ( ) => {
286
+ // read fixture startgroupRobots.txt
287
+ const robotsTxt = await fsp . readFile ( './test/fixtures/startgroupRobots.txt' , { encoding : 'utf-8' } )
288
+ expect ( parseRobotsTxt ( robotsTxt ) ) . toMatchInlineSnapshot ( `
289
+ {
290
+ "groups": [
291
+ {
292
+ "allow": [
293
+ "/bar",
294
+ ],
295
+ "comment": [],
296
+ "disallow": [
297
+ "/foo",
298
+ ],
299
+ "userAgent": [
300
+ "ExampleBot",
301
+ ],
302
+ },
303
+ {
304
+ "allow": [
305
+ "/boo",
306
+ ],
307
+ "comment": [],
308
+ "disallow": [
309
+ "/baz",
310
+ ],
311
+ "userAgent": [
312
+ "examplebot",
313
+ ],
314
+ },
315
+ {
316
+ "allow": [],
317
+ "comment": [],
318
+ "disallow": [
319
+ "/invalid",
320
+ ],
321
+ "userAgent": [
322
+ "",
323
+ ],
324
+ },
325
+ {
326
+ "allow": [],
327
+ "comment": [],
328
+ "disallow": [
329
+ "/star",
330
+ ],
331
+ "userAgent": [
332
+ "*",
333
+ ],
334
+ },
335
+ ],
336
+ "sitemaps": [],
337
+ }
338
+ ` )
339
+ } )
284
340
} )
You can’t perform that action at this time.
0 commit comments