BearND has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/385424 )

Change subject: Fail incomplete sections early
......................................................................

Fail incomplete sections early

To avoid issues with incomplete sections, which let to T175305,
the sectioning code now throws an 502 HTTP error code
("unsupported_section") when a section without heading is encountered.
The exception to this is the lead section, which never should have a
heading.

Change-Id: I6535f4884b2a77609338a5215f1ddf877d24f98d
---
M lib/parsoidSectionsUsingSectionTags.js
M test/lib/parsoid/parsoid-sections-section-elements-tests.js
2 files changed, 19 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/24/385424/1

diff --git a/lib/parsoidSectionsUsingSectionTags.js 
b/lib/parsoidSectionsUsingSectionTags.js
index 8b6a29f..96ba0ef 100644
--- a/lib/parsoidSectionsUsingSectionTags.js
+++ b/lib/parsoidSectionsUsingSectionTags.js
@@ -1,6 +1,8 @@
 'use strict';
 
 const parsoidDomUtils = require('parsoid-dom-utils');
+const sUtil = require('./util');
+const HTTPError = sUtil.HTTPError;
 
 /**
  * @deprecated wait for Parsoid to implement this.
@@ -79,9 +81,15 @@
             currentSection.toclevel = parseInt(childEl.tagName.charAt(1), 10) 
- 1;
             currentSection.line = childEl.innerHTML.trim();
             currentSection.anchor = childEl.getAttribute('id');
+            sections.push(currentSection);
+        } else {
+            throw new HTTPError({
+                status: 502,
+                type: 'unsupported_section',
+                title: 'Section structure not supported',
+                detail: `Cannot find heading for section number 
${currentSection.id}. ${childEl.tagName} not a heading.` // eslint-disable-line 
max-len
+            });
         }
-
-        sections.push(currentSection);
     }
 
     return sections;
diff --git a/test/lib/parsoid/parsoid-sections-section-elements-tests.js 
b/test/lib/parsoid/parsoid-sections-section-elements-tests.js
index 3c94847..c511943 100644
--- a/test/lib/parsoid/parsoid-sections-section-elements-tests.js
+++ b/test/lib/parsoid/parsoid-sections-section-elements-tests.js
@@ -94,5 +94,14 @@
         assertSection1(sections, sectionInDiv);
     });
 
+    it('non-lead section without heading tag should throw error', () => {
+        const doc = domino.createDocument(
+            '<section data-section-number="0">text0</section>' +
+            '<section data-section-number="1">text1</section>');
+        assert.throws(() => {
+            parsoidSectionsUsingSectionTags.getSectionsText(doc);
+        }, /unsupported_section/);
+    });
+
     /* eslint-enable prefer-template */
 });

-- 
To view, visit https://gerrit.wikimedia.org/r/385424
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6535f4884b2a77609338a5215f1ddf877d24f98d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND <bsitzm...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to