Skip to content

Commit

Permalink
Fix false positive alert with x-default hreflang tag
Browse files Browse the repository at this point in the history
  • Loading branch information
StJudeWasHere committed Feb 19, 2024
1 parent cd24f09 commit c566ea2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/html_parser/html_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestPageReportHTML(t *testing.T) {
{want: 6, got: len(pageReport.Links)},
{want: 1, got: len(pageReport.ExternalLinks)},
{want: 10, got: pageReport.Words},
{want: 1, got: len(pageReport.Hreflangs)},
{want: 2, got: len(pageReport.Hreflangs)},
{want: 7, got: len(pageReport.Images)},
{want: 1, got: len(pageReport.Scripts)},
{want: 1, got: len(pageReport.Styles)},
Expand Down
1 change: 1 addition & 0 deletions internal/html_parser/testdata/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="robots" content="noindex, nofollow" />
<link rel="canonical" href="/canonical/" />
<link rel="alternate" href="https://example.com/fr" hreflang="fr" />
<link rel="alternate" href="https://example.com/" hreflang="x-default" />
<script src="/js/app.js"></script>
<link rel="stylesheet" href="/css/style.css">
</head>
Expand Down
2 changes: 1 addition & 1 deletion internal/report_manager/reporters/hreflangs.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewHreflangMismatchingLang() *report_manager.PageIssueReporter {
}

for _, hl := range pageReport.Hreflangs {
if hl.URL == pageReport.URL && hl.Lang != pageReport.Lang {
if hl.URL == pageReport.URL && hl.Lang != "x-default" && hl.Lang != pageReport.Lang {
return true
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/report_manager/reporters/hreflangs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestHreflangMismatchingLangNoIssues(t *testing.T) {
URL: "http://example.com",
Hreflangs: []models.Hreflang{
{URL: "http://example.com", Lang: "en"},
{URL: "http://example.com", Lang: "x-default"},
{URL: "http://example.com/fr", Lang: "fr"},
},
}
Expand Down Expand Up @@ -183,6 +184,7 @@ func TestHreflangMismatchingLangIssues(t *testing.T) {
URL: "http://example.com",
Hreflangs: []models.Hreflang{
{URL: "http://example.com", Lang: "en"},
{URL: "http://example.com", Lang: "x-default"},
{URL: "http://example.com/fr", Lang: "fr"},
},
}
Expand Down

0 comments on commit c566ea2

Please sign in to comment.