mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 03:42:38 +00:00
Merge pull request #3560 from G-Ambatte/fixAttributeLeaking-#3559
Limit htmlString to the first element ONLY
This commit is contained in:
@@ -787,11 +787,13 @@ const processStyleTags = (string)=>{
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Given a string representing an HTML element, extract all of its properties (id, class, style, and other attributes)
|
||||||
const extractHTMLStyleTags = (htmlString)=>{
|
const extractHTMLStyleTags = (htmlString)=>{
|
||||||
const id = htmlString.match(/id="([^"]*)"/)?.[1] || null;
|
const firstElementOnly = htmlString.split('>')[0];
|
||||||
const classes = htmlString.match(/class="([^"]*)"/)?.[1] || null;
|
const id = firstElementOnly.match(/id="([^"]*)"/)?.[1] || null;
|
||||||
const styles = htmlString.match(/style="([^"]*)"/)?.[1] || null;
|
const classes = firstElementOnly.match(/class="([^"]*)"/)?.[1] || null;
|
||||||
const attributes = htmlString.match(/[a-zA-Z]+="[^"]*"/g)
|
const styles = firstElementOnly.match(/style="([^"]*)"/)?.[1] || null;
|
||||||
|
const attributes = firstElementOnly.match(/[a-zA-Z]+="[^"]*"/g)
|
||||||
?.filter((attr)=>!attr.startsWith('class="') && !attr.startsWith('style="') && !attr.startsWith('id="'))
|
?.filter((attr)=>!attr.startsWith('class="') && !attr.startsWith('style="') && !attr.startsWith('id="'))
|
||||||
.reduce((obj, attr)=>{
|
.reduce((obj, attr)=>{
|
||||||
const index = attr.indexOf('=');
|
const index = attr.indexOf('=');
|
||||||
|
|||||||
@@ -333,6 +333,13 @@ describe('Injection: When an injection tag follows an element', ()=>{
|
|||||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<p><span class="inline-block" style="color:red;">text</span>{background:blue}</p>');
|
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<p><span class="inline-block" style="color:red;">text</span>{background:blue}</p>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Renders an parent and child element, each modified by an injector', function() {
|
||||||
|
const source = dedent`**bolded text**{color:red}
|
||||||
|
{color:blue}`;
|
||||||
|
const rendered = Markdown.render(source).trimReturns();
|
||||||
|
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<p style="color:blue;"><strong style="color:red;">bolded text</strong></p>');
|
||||||
|
});
|
||||||
|
|
||||||
it('Renders an image with added attributes', function() {
|
it('Renders an image with added attributes', function() {
|
||||||
const source = ` {position:absolute,bottom:20px,left:130px,width:220px,a="b and c",d=e}`;
|
const source = ` {position:absolute,bottom:20px,left:130px,width:220px,a="b and c",d=e}`;
|
||||||
const rendered = Markdown.render(source).trimReturns();
|
const rendered = Markdown.render(source).trimReturns();
|
||||||
|
|||||||
Reference in New Issue
Block a user