Skip to content

Commit

Permalink
fix(parser): tag inside tag parsing regression (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiLiZART committed Dec 15, 2020
1 parent b131d5f commit 09bda26
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/bbob-parser/src/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ function createLexer(buffer, options = {}) {
const tagGrabber = createCharGrabber(tagStr, { onSkip });
const hasSpace = tagGrabber.includes(SPACE);

tagMode = TAG_STATE_NAME;

while (tagGrabber.hasNext()) {
tagMode = nextTagState(tagGrabber, !hasSpace);
}
Expand Down Expand Up @@ -307,6 +309,8 @@ function createLexer(buffer, options = {}) {
}

function tokenize() {
stateMode = STATE_WORD;

while (chars.hasNext()) {
switch (stateMode) {
case STATE_TAG:
Expand Down
37 changes: 37 additions & 0 deletions packages/bbob-parser/test/lexer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,43 @@ describe('lexer', () => {
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', () => {
const input = '"Someone Like You" by Adele';
Expand Down
38 changes: 38 additions & 0 deletions packages/bbob-parser/test/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]', () => {
const ast = parse('[url href=https://docs.google.com/spreadsheets/d/1W9VPUESF_NkbSa_HtRFrQNl0nYo8vPCxJFy7jD3Tpio/edit#gid=0]Docs[/url]');

Expand Down

0 comments on commit 09bda26

Please sign in to comment.