mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-17 19:21:20 +03:00
fix(parser): tag inside tag parsing regression (#81)
This commit is contained in:
committed by
GitHub
parent
b131d5f78d
commit
09bda26d7c
@@ -235,6 +235,8 @@ function createLexer(buffer, options = {}) {
|
|||||||
const tagGrabber = createCharGrabber(tagStr, { onSkip });
|
const tagGrabber = createCharGrabber(tagStr, { onSkip });
|
||||||
const hasSpace = tagGrabber.includes(SPACE);
|
const hasSpace = tagGrabber.includes(SPACE);
|
||||||
|
|
||||||
|
tagMode = TAG_STATE_NAME;
|
||||||
|
|
||||||
while (tagGrabber.hasNext()) {
|
while (tagGrabber.hasNext()) {
|
||||||
tagMode = nextTagState(tagGrabber, !hasSpace);
|
tagMode = nextTagState(tagGrabber, !hasSpace);
|
||||||
}
|
}
|
||||||
@@ -307,6 +309,8 @@ function createLexer(buffer, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function tokenize() {
|
function tokenize() {
|
||||||
|
stateMode = STATE_WORD;
|
||||||
|
|
||||||
while (chars.hasNext()) {
|
while (chars.hasNext()) {
|
||||||
switch (stateMode) {
|
switch (stateMode) {
|
||||||
case STATE_TAG:
|
case STATE_TAG:
|
||||||
|
|||||||
@@ -122,6 +122,43 @@ describe('lexer', () => {
|
|||||||
expect(tokens).toBeMantchOutput(output);
|
expect(tokens).toBeMantchOutput(output);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('tags with single word and camel case params', () => {
|
||||||
|
const input = `[url href="/groups/123/" isNowrap=true isTextOverflow=true state=primary]
|
||||||
|
[avatar href="/avatar/4/3/b/1606.jpg@20x20?cache=1561462725&bgclr=ffffff" size=xs][/avatar]
|
||||||
|
Group Name Go[/url] `;
|
||||||
|
const tokens = tokenize(input);
|
||||||
|
|
||||||
|
const output = [
|
||||||
|
[TYPE.TAG, 'url', '0', '0'],
|
||||||
|
[TYPE.ATTR_NAME, 'href', '0', '0'],
|
||||||
|
[TYPE.ATTR_VALUE, '/groups/123/', '0', '0'],
|
||||||
|
[TYPE.ATTR_NAME, 'isNowrap', '0', '0'],
|
||||||
|
[TYPE.ATTR_VALUE, 'true', '0', '0'],
|
||||||
|
[TYPE.ATTR_NAME, 'isTextOverflow', '0', '0'],
|
||||||
|
[TYPE.ATTR_VALUE, 'true', '0', '0'],
|
||||||
|
[TYPE.ATTR_NAME, 'state', '0', '0'],
|
||||||
|
[TYPE.ATTR_VALUE, 'primary', '0', '0'],
|
||||||
|
[TYPE.NEW_LINE, '\n', '0', '0'],
|
||||||
|
[TYPE.SPACE, ' ', '0', '0'],
|
||||||
|
[TYPE.TAG, 'avatar', '0', '0'],
|
||||||
|
[TYPE.ATTR_NAME, 'href', '0', '0'],
|
||||||
|
[TYPE.ATTR_VALUE, '/avatar/4/3/b/1606.jpg@20x20?cache=1561462725&bgclr=ffffff', '0', '0'],
|
||||||
|
[TYPE.ATTR_NAME, 'size', '0', '0'],
|
||||||
|
[TYPE.ATTR_VALUE, 'xs', '0', '0'],
|
||||||
|
[TYPE.TAG, '/avatar', '0', '0'],
|
||||||
|
[TYPE.NEW_LINE, '\n', '0', '0'],
|
||||||
|
[TYPE.SPACE, ' ', '0', '0'],
|
||||||
|
[TYPE.WORD, 'Group', '0', '0'],
|
||||||
|
[TYPE.SPACE, ' ', '0', '0'],
|
||||||
|
[TYPE.WORD, 'Name', '0', '0'],
|
||||||
|
[TYPE.SPACE, ' ', '0', '0'],
|
||||||
|
[TYPE.WORD, 'Go', '0', '0'],
|
||||||
|
[TYPE.TAG, '/url', '0', '0'],
|
||||||
|
[TYPE.SPACE, ' ', '0', '0'],
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(tokens).toBeMantchOutput(output);
|
||||||
|
});
|
||||||
|
|
||||||
test('string with quotemarks', () => {
|
test('string with quotemarks', () => {
|
||||||
const input = '"Someone Like You" by Adele';
|
const input = '"Someone Like You" by Adele';
|
||||||
|
|||||||
@@ -214,6 +214,44 @@ describe('Parser', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('parse tag with camelCase params', () => {
|
||||||
|
const ast = parse(`[url href="/groups/123/" isNowrap=true isTextOverflow=true state=primary]
|
||||||
|
[avatar href="/avatar/4/3/b/1606.jpg@20x20?cache=1561462725&bgclr=ffffff" size=xs][/avatar]
|
||||||
|
Group Name Go[/url] `);
|
||||||
|
|
||||||
|
expectOutput(ast, [
|
||||||
|
{
|
||||||
|
tag: 'url',
|
||||||
|
attrs: {
|
||||||
|
href: '/groups/123/',
|
||||||
|
isNowrap: 'true',
|
||||||
|
isTextOverflow: 'true',
|
||||||
|
state: 'primary'
|
||||||
|
},
|
||||||
|
content: [
|
||||||
|
'\n',
|
||||||
|
' ',
|
||||||
|
{
|
||||||
|
tag: 'avatar',
|
||||||
|
attrs: {
|
||||||
|
href: '/avatar/4/3/b/1606.jpg@20x20?cache=1561462725&bgclr=ffffff',
|
||||||
|
size: 'xs'
|
||||||
|
},
|
||||||
|
content: []
|
||||||
|
},
|
||||||
|
'\n',
|
||||||
|
' ',
|
||||||
|
'Group',
|
||||||
|
' ',
|
||||||
|
'Name',
|
||||||
|
' ',
|
||||||
|
'Go',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
' ',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('parse url tag with # and = symbols [google docs]', () => {
|
test('parse url tag with # and = symbols [google docs]', () => {
|
||||||
const ast = parse('[url href=https://docs.google.com/spreadsheets/d/1W9VPUESF_NkbSa_HtRFrQNl0nYo8vPCxJFy7jD3Tpio/edit#gid=0]Docs[/url]');
|
const ast = parse('[url href=https://docs.google.com/spreadsheets/d/1W9VPUESF_NkbSa_HtRFrQNl0nYo8vPCxJFy7jD3Tpio/edit#gid=0]Docs[/url]');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user