From c566ea28a308557f59461e3b5d9a0b2793fa805a Mon Sep 17 00:00:00 2001 From: StJudeWasHere <707925+StJudeWasHere@users.noreply.github.com> Date: Mon, 19 Feb 2024 12:10:49 +0100 Subject: [PATCH] Fix false positive alert with x-default hreflang tag --- internal/html_parser/html_parser_test.go | 2 +- internal/html_parser/testdata/test.html | 1 + internal/report_manager/reporters/hreflangs.go | 2 +- internal/report_manager/reporters/hreflangs_test.go | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/html_parser/html_parser_test.go b/internal/html_parser/html_parser_test.go index b57f3937..a134e72c 100644 --- a/internal/html_parser/html_parser_test.go +++ b/internal/html_parser/html_parser_test.go @@ -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)}, diff --git a/internal/html_parser/testdata/test.html b/internal/html_parser/testdata/test.html index eec17484..93daa427 100644 --- a/internal/html_parser/testdata/test.html +++ b/internal/html_parser/testdata/test.html @@ -6,6 +6,7 @@ + diff --git a/internal/report_manager/reporters/hreflangs.go b/internal/report_manager/reporters/hreflangs.go index 71976905..c171f653 100644 --- a/internal/report_manager/reporters/hreflangs.go +++ b/internal/report_manager/reporters/hreflangs.go @@ -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 } } diff --git a/internal/report_manager/reporters/hreflangs_test.go b/internal/report_manager/reporters/hreflangs_test.go index 60b1d5c1..8af7c074 100644 --- a/internal/report_manager/reporters/hreflangs_test.go +++ b/internal/report_manager/reporters/hreflangs_test.go @@ -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"}, }, } @@ -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"}, }, }