shortcode-tree
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -58,3 +58,11 @@ "use strict"; | ||
if (options.precise && !shortcode.isSelfClosing) { | ||
if (shortcode.isSelfClosing && input.substr(openBlockTextFull.length, closingTagExpected.length) === closingTagExpected) { | ||
// Special case: misbehaving little bugger claims to be improperly self-closing, but decided to close itself | ||
// anyway. I've seen this happen in the wild, and it sucks, so we'll try to deal with it. | ||
var closingTagIdx = openBlockTextFull.length; | ||
var offsetFromEnd = input.length - closingTagExpected.length - closingTagIdx; | ||
shortcode.content = input.substr(openBlockStartIdx + openBlockTextFull.length, input.length - openBlockTextFull.length - closingTagExpected.length - offsetFromEnd); | ||
shortcode.codeText = input.substr(openBlockStartIdx, input.length - offsetFromEnd); | ||
} else if (options.precise && !shortcode.isSelfClosing) { | ||
var stackLevel = 0; | ||
@@ -133,8 +141,8 @@ | ||
} else { | ||
var offsetFromEnd = 0; | ||
var _offsetFromEnd = 0; | ||
if (!shortcode.isSelfClosing) { | ||
var closingTagIdx = input.indexOf(closingTagExpected); | ||
var _closingTagIdx = input.indexOf(closingTagExpected); | ||
if (closingTagIdx === -1) { | ||
if (_closingTagIdx === -1) { | ||
if (options.throwErrors) { | ||
@@ -147,6 +155,6 @@ throw new Error("Malformatted shortcode: Expected closing tag: " + closingTagExpected); | ||
offsetFromEnd = input.length - closingTagExpected.length - closingTagIdx; | ||
_offsetFromEnd = input.length - closingTagExpected.length - _closingTagIdx; | ||
shortcode.content = input.substr(openBlockStartIdx + openBlockTextFull.length, input.length - openBlockTextFull.length - closingTagExpected.length - offsetFromEnd); | ||
shortcode.codeText = input.substr(openBlockStartIdx, input.length - offsetFromEnd); | ||
shortcode.content = input.substr(openBlockStartIdx + openBlockTextFull.length, input.length - openBlockTextFull.length - closingTagExpected.length - _offsetFromEnd); | ||
shortcode.codeText = input.substr(openBlockStartIdx, input.length - _offsetFromEnd); | ||
} else { | ||
@@ -153,0 +161,0 @@ shortcode.content = null; |
{ | ||
"name": "shortcode-tree", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Parser library for reading short codes (BB codes) into a tree structure", | ||
@@ -9,3 +9,3 @@ "main": "dist/index.js", | ||
"build": "babel src --presets babel-preset-es2015 --out-dir dist", | ||
"prepublishOnly": "npm run build" | ||
"prepare": "npm run build" | ||
}, | ||
@@ -12,0 +12,0 @@ "author": "Roy de Jong <roy@softwarepunt.nl>", |
@@ -184,2 +184,10 @@ let ShortcodeParser = require('../src').ShortcodeParser; | ||
}); | ||
it('supports parsing self-closing tags without valid syntax, with list supplement, without tripping over tags that decide to have a closer anyway', function () { | ||
let testInput = `[img src="what.jpg" standards="no"][/img] asdf`; | ||
let expectedOutput = new Shortcode('img', "", {"src": "what.jpg", "standards": "no"}, true, `[img src="what.jpg" standards="no"][/img]`, 0); | ||
let actualOutput = ShortcodeParser.parseShortcode(testInput, { selfClosingTags: ["img"] }) || null; | ||
expect(actualOutput).to.deep.equal(expectedOutput); | ||
}); | ||
}); | ||
@@ -186,0 +194,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67476
1182