Skip to content

Commit da9bdaf

Browse files
committed
Handle redirects in Validator
1 parent 6741e20 commit da9bdaf

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

lib/src/validator.dart

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ class Validator {
2626

2727
final Map<String, Set<ModelElement>> _hrefs;
2828

29+
/// The set of files that have already been visited.
2930
final Set<String> _visited = {};
3031

32+
/// The set of files that simply redirect to a different file.
33+
final Set<String> _redirects = {};
34+
3135
Validator(this._packageGraph, this._config, String origin, this._writtenFiles,
3236
this._onCheckProgress)
3337
: _origin = path.normalize(origin),
@@ -60,8 +64,11 @@ class Validator {
6064
_visited.remove(fullPath);
6165
return;
6266
}
67+
var _PageData(:links, :baseHref, :isRedirect) = pageLinks;
6368
_visited.add(fullPath);
64-
var (links, baseHref) = pageLinks;
69+
if (isRedirect) {
70+
_redirects.add(fullPath);
71+
}
6572

6673
// Prevent extremely large stacks by storing the paths we are using
6774
// here instead -- occasionally, very large jobs have overflowed
@@ -166,7 +173,7 @@ class Validator {
166173
found.add(href);
167174
}
168175
}
169-
final missingFromSearch = _visited.difference(found);
176+
final missingFromSearch = _visited.difference(_redirects).difference(found);
170177
for (final missingFile in missingFromSearch) {
171178
_warn(PackageWarning.missingFromSearchIndex, missingFile, _origin,
172179
referredFrom: fullPath);
@@ -178,7 +185,7 @@ class Validator {
178185
///
179186
/// This is extracted to save memory during the check; be careful not to hang
180187
/// on to anything referencing the full file and doc tree.
181-
(Set<String> links, String? baseHref)? _getLinksAndBaseHref(String fullPath) {
188+
_PageData? _getLinksAndBaseHref(String fullPath) {
182189
final file = _config.resourceProvider.getFile(fullPath);
183190
if (!file.exists) {
184191
return null;
@@ -209,8 +216,17 @@ class Validator {
209216
? path.url.join(uri, 'index.html')
210217
: uri)
211218
.toSet();
219+
var refreshTag = doc
220+
.querySelectorAll('meta')
221+
.firstWhereOrNull((e) => e.attributes['http-equiv'] == 'refresh');
222+
if (refreshTag != null) {
223+
var refreshUrl = refreshTag.attributes['url'];
224+
if (refreshUrl != null) {
225+
stringLinks.add(refreshUrl);
226+
}
227+
}
212228

213-
return (stringLinks, baseHref);
229+
return _PageData(stringLinks, baseHref, refreshTag != null);
214230
}
215231

216232
/// Warns on erroneous file paths.
@@ -252,3 +268,12 @@ class Validator {
252268
message: message, referredFrom: referredFromElements);
253269
}
254270
}
271+
272+
/// Various data found in a given generate page
273+
class _PageData {
274+
final Set<String> links;
275+
final String? baseHref;
276+
final bool isRedirect;
277+
278+
const _PageData(this.links, this.baseHref, this.isRedirect);
279+
}

0 commit comments

Comments
 (0)