Skip to content

Commit

Permalink
Do not report missing lang attribute on redirect urls
Browse files Browse the repository at this point in the history
  • Loading branch information
StJudeWasHere committed Oct 23, 2024
1 parent 5456ec2 commit 61ebd57
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/issues/page/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func NewInvalidLangReporter() *models.PageIssueReporter {
return false
}

if pageReport.StatusCode >= 300 && pageReport.StatusCode < 400 {
return false
}

if pageReport.Lang == "" {
return false
}
Expand Down Expand Up @@ -56,6 +60,10 @@ func NewMissingLangReporter() *models.PageIssueReporter {
return false
}

if pageReport.StatusCode >= 300 && pageReport.StatusCode < 400 {
return false
}

return pageReport.Lang == ""
}

Expand Down
43 changes: 43 additions & 0 deletions internal/issues/page/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ func TestInvalidLangIssues(t *testing.T) {
}
}

// Test the InvalidLang reporter with a PageReport that has a redirect status code.
// The reporter should not report the issue.
func TestInvalidLang30xNoIssues(t *testing.T) {
pageReport := &models.PageReport{
Crawled: true,
MediaType: "text/html",
Lang: "InvalidLangCode",
StatusCode: 301,
}

reporter := page.NewInvalidLangReporter()
if reporter.ErrorType != errors.ErrorInvalidLanguage {
t.Errorf("TestNoIssues: error type is not correct")
}

reportsIssue := reporter.Callback(pageReport, &html.Node{}, &http.Header{})

if reportsIssue == true {
t.Errorf("TestInvalidLangIssues: reportsIssue should be false")
}
}

// Test the MissingLang reporter with a PageReport that has a language attribute.
// The reporter should not report the issue.
func TestMissingLangNoIssues(t *testing.T) {
Expand All @@ -74,6 +96,27 @@ func TestMissingLangNoIssues(t *testing.T) {
}
}

// Test the MissingLang reporter with a PageReport that has a redirect status code.
// The reporter should not report the issue.
func TestMissingLang30xNoIssues(t *testing.T) {
pageReport := &models.PageReport{
Crawled: true,
MediaType: "text/html",
StatusCode: 301,
}

reporter := page.NewMissingLangReporter()
if reporter.ErrorType != errors.ErrorNoLang {
t.Errorf("TestNoIssues: error type is not correct")
}

reportsIssue := reporter.Callback(pageReport, &html.Node{}, &http.Header{})

if reportsIssue == true {
t.Errorf("TestMissingLangNoIssues: reportsIssue should be false")
}
}

// Test the MissingLang reporter with a PageReport that has an empty language attribute.
// The reporter should report the issue.
func TestMissingLangIssues(t *testing.T) {
Expand Down

0 comments on commit 61ebd57

Please sign in to comment.