Skip to content

Commit 87bd03e

Browse files
authored
Detect library hrefs with or without ending slash. (#1424)
* Detect library hrefs with or without ending slash. * Only filter last segment.
1 parent 840f2c3 commit 87bd03e

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/src/dartdoc/dartdoc_internals.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ bool isHrefALibrary(String? href) {
1717
if (href.endsWith('.html')) {
1818
return false;
1919
}
20-
// libraries have no slash in their hrefs
21-
return !href.contains('/');
20+
final segments = href.split('/');
21+
// remove if the last segment is empty, indicating a trailing slash
22+
if (segments.last.isEmpty) {
23+
segments.removeLast();
24+
}
25+
// libraries have only a single segment
26+
return segments.length == 1;
2227
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:pana/src/dartdoc/dartdoc_internals.dart';
6+
import 'package:test/test.dart';
7+
8+
void main() {
9+
group('dartdoc internals', () {
10+
test('isHrefALibrary: negative', () async {
11+
expect(isHrefALibrary(null), false);
12+
expect(isHrefALibrary(''), false);
13+
expect(isHrefALibrary('index.html'), false);
14+
expect(isHrefALibrary('retry.html'), false);
15+
expect(isHrefALibrary('retry/retry.html'), false);
16+
expect(isHrefALibrary('a/b'), false);
17+
});
18+
19+
test('isHrefALibrary: positive', () async {
20+
expect(isHrefALibrary('x/x-library.html'), true);
21+
expect(isHrefALibrary('x'), true);
22+
expect(isHrefALibrary('x/'), true);
23+
});
24+
});
25+
}

0 commit comments

Comments
 (0)