Skip to content

Commit

Permalink
Detect library hrefs with or without ending slash. (#1424)
Browse files Browse the repository at this point in the history
* Detect library hrefs with or without ending slash.

* Only filter last segment.
  • Loading branch information
isoos authored Nov 28, 2024
1 parent 840f2c3 commit 87bd03e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/src/dartdoc/dartdoc_internals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ bool isHrefALibrary(String? href) {
if (href.endsWith('.html')) {
return false;
}
// libraries have no slash in their hrefs
return !href.contains('/');
final segments = href.split('/');
// remove if the last segment is empty, indicating a trailing slash
if (segments.last.isEmpty) {
segments.removeLast();
}
// libraries have only a single segment
return segments.length == 1;
}
25 changes: 25 additions & 0 deletions test/dartdoc/dartdoc_internals_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:pana/src/dartdoc/dartdoc_internals.dart';
import 'package:test/test.dart';

void main() {
group('dartdoc internals', () {
test('isHrefALibrary: negative', () async {
expect(isHrefALibrary(null), false);
expect(isHrefALibrary(''), false);
expect(isHrefALibrary('index.html'), false);
expect(isHrefALibrary('retry.html'), false);
expect(isHrefALibrary('retry/retry.html'), false);
expect(isHrefALibrary('a/b'), false);
});

test('isHrefALibrary: positive', () async {
expect(isHrefALibrary('x/x-library.html'), true);
expect(isHrefALibrary('x'), true);
expect(isHrefALibrary('x/'), true);
});
});
}

0 comments on commit 87bd03e

Please sign in to comment.