svenslaggare / bbcodeparser Goto Github PK
View Code? Open in Web Editor NEWBB code parser written in TypeScript.
License: MIT License
BB code parser written in TypeScript.
License: MIT License
Hi I've noticed that there are some differences between the git repo and npm package.
For example in tokenizer.ts
the var attrValueChars
have more characters and in NPM they're the same as attrNameChars
which breaks my application (I need hash symbols for links).
Can someone republish npm package please? @svenslaggare
Otherwise, I'd be happy to take over this repo if noone's willing to keep working on it.
Hi,
We came across this as we use this module to render bbCode within our forums.
We noticed that this string in particular hangs:
var parser = new BBCodeParser({}).parseString("[HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft SDKsSilverlightv4.0AssemblyFoldersEx]");
This is a registry key, so I can definitely see it causing some screwiness somewhere. I thought it would be ignored but it seems to never actually go into the parseString function, it will simply hang in limbo.
Anyway to prevent this?
Thanks!
Seems that the latest is 1.0.10 from 3 years ago. Stumbled upon the double quotes problem for the attributes that seems to be not updated in npm.
Nearly all BBCode engines I've used in the past use the following format:
[list]
[*]List item 1
[*]List item 2
[*]List item 3
[/list]
Same as:
<ul>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ul>
But this is impossible with the parser in its current set up. I can have a look to alter it one day, but I don't know if I'll find the time. Can you help with this?
In node.js, I have a error when I typed
> var BBCodeParser = require('bbcode-parser');
undefined
> var parser = new BBCodeParser(BBCodeParser.defaultTags());
undefined
> parser.parseString('[b]Bold text[/b]');
'<b>Bold text</b>'
> parser.parseString('[]Bold text[/b]');
TypeError: Cannot read property 'isValid' of null
at BBCodeParser.parseString (/tmp/node_modules/bbcode-parser/bbCodeParser.js:50:23)
at repl:1:8
at REPLServer.defaultEval (repl.js:132:27)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:279:12)
at REPLServer.emit (events.js:107:17)
at REPLServer.Interface._onLine (readline.js:214:10)
at REPLServer.Interface._line (readline.js:553:8)
at REPLServer.Interface._ttyWrite (readline.js:830:14)
I solved it by changing isValid
method in bbCodeParserTree.js
, like that :
BBCodeParseTree.prototype.isValid = function () {
//An tree without subtrees is valid
if (this.subTrees.length == 0) {
return true;
}
this.subTrees.forEach( function(value,i){
var currentTree = value//this.subTrees[i];
if ( currentTree == null || !currentTree.isValid()) {
return false;
}
})
return true;
};
Is this solution the good one ?
As always, I import modules in the app.module.ts
, but for some reason bbcode-parseq is not displayed as existing for me.
Is there anyway to simply strip all bbcode tags from a string?
I am trying to create a custom tag, but am getting BBTag is not defined
.
import BBCodeParser from 'bbcode-parser'
let bbTags = {}
bbTags["p"] = new BBTag("p", true, false, false);
const customTagParser = new BBCodeParser(bbTags)
How can I get access to the BBTag constructor in Node?
Sometimes I pass in undefined or null, I know this is bad, but your script should not die on those errors.
parser.parseString(null, true);
The Regex match forces Double quotes around token attributes. If any attribute exists without quotes around it the entire tree fails as it doesn't tokenize it properly:
var attrPattern = new RegExp("(" + attrNameChars + "+)?=\"(" + attrValueChars + "*)\"", "g");
Due to the URL of [img] tags not being checked, one could type:
[img]test.jpg" onError="alert('hi')[/img]]
Which shows existence of a possible XSS exploit. This is a critical issue in my opinion, and one that should be fixed ASAP.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.