From 112853c13d12585ae598ce340600060bd543d3cb Mon Sep 17 00:00:00 2001 From: Michael Lissner Date: Tue, 6 Aug 2019 17:16:14 -0400 Subject: [PATCH] fix(page handling): Only show restriction warning on doc1 pages Previously, we saw that our regexes could be a little over-zealous, matching on pages that have nothing to do with downloading documents. This change makes it so they only match on doc1 (or similar) pages. Fixes: freelawproject/recap#265 --- spec/ContentDelegateSpec.js | 18 +++++++++++++----- src/content_delegate.js | 6 ++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/spec/ContentDelegateSpec.js b/spec/ContentDelegateSpec.js index c7a30b6f..95750785 100644 --- a/spec/ContentDelegateSpec.js +++ b/spec/ContentDelegateSpec.js @@ -62,6 +62,7 @@ describe('The ContentDelegate class', function() { describe('ContentDelegate constructor', function() { const expected_url = 'https://ecf.canb.uscourts.gov/cgi-bin/DktRpt.pl?531591'; + const restricted_url = 'https://ecf.canb.uscourts.gov/doc1/04503837920'; const expected_path = '/cgi-bin/DktRpt.pl?531591'; const expected_court = 'canb'; const expected_pacer_case_id = '531591'; @@ -88,6 +89,7 @@ describe('The ContentDelegate class', function() { it('should flag restriction for Warning!', function () { const form = document.createElement('form'); const input = document.createElement('input'); + input.value = 'View Document'; form.appendChild(input); document.body.appendChild(form); @@ -97,10 +99,10 @@ describe('The ContentDelegate class', function() { table.appendChild(table_tr); table_tr.appendChild(table_td); document.body.appendChild(table); - table_td.textContent = "Warning!"; + table_td.textContent = "Warning! Image"; expect(document.body.innerText).not.toContain('will not be uploaded'); - const cd = new ContentDelegate(expected_url, expected_path, expected_court, + const cd = new ContentDelegate(restricted_url, expected_path, expected_court, expected_pacer_case_id, expected_pacer_doc_id, expected_links); expect(cd.restricted).toBe(true); expect(document.body.innerText).toContain('will not be uploaded'); @@ -111,9 +113,14 @@ describe('The ContentDelegate class', function() { it('should flag restriction for bold restriction', function () { const form = document.createElement('form'); const input = document.createElement('input'); + input.value = 'View Document'; form.appendChild(input); document.body.appendChild(form); + const table_td = document.createElement('td'); + document.body.appendChild(table_td); + table_td.textContent = "Image"; + const paragraph = document.createElement('p'); const bold = document.createElement('b'); paragraph.appendChild(bold); @@ -121,7 +128,7 @@ describe('The ContentDelegate class', function() { bold.textContent = "SEALED"; expect(document.body.innerText).not.toContain('will not be uploaded'); - const cd = new ContentDelegate(expected_url, expected_path, expected_court, + const cd = new ContentDelegate(restricted_url, expected_path, expected_court, expected_pacer_case_id, expected_pacer_doc_id, expected_links); expect(cd.restricted).toBe(true); expect(document.body.innerText).toContain('will not be uploaded'); @@ -997,13 +1004,14 @@ describe('The ContentDelegate class', function() { 'https://ecf.canb.uscourts.gov/doc1/034031424909', 'https://ecf.canb.uscourts.gov/doc1/034031438754', ]; + const expected_url = 'https://ecf.canb.uscourts.gov/cgi-bin/DktRpt.pl?531591'; describe('when there are no valid urls', function() { let links; let cd; beforeEach(function() { links = linksFromUrls(fake_urls); - cd = new ContentDelegate(null, null, null, null, null, links); + cd = new ContentDelegate(expected_url, null, null, null, null, links); cd.attachRecapLinkToEligibleDocs(); }); @@ -1018,7 +1026,7 @@ describe('The ContentDelegate class', function() { beforeEach(function() { links = linksFromUrls(urls); $('body').append(links); - cd = new ContentDelegate(null, null, null, null, null, links); + cd = new ContentDelegate(expected_url, null, null, null, null, links); cd.pacer_doc_ids = [ 1234 ]; }); diff --git a/src/content_delegate.js b/src/content_delegate.js index 7711aca6..09c1c199 100644 --- a/src/content_delegate.js +++ b/src/content_delegate.js @@ -48,6 +48,12 @@ ContentDelegate.prototype.checkRestrictions = function() { // "document is restricted", "SEALED", or "do not allow it to be seen". // Case-insensitively. + // The regexes below are pretty broad by design. + // Only trigger this code on doc1 pages. + if (!PACER.isSingleDocumentPage(this.url, document)) { + return false; + } + let restrictedDoc = false; for (let td of