<commit_before>set_global('blueslip', global.make_zblueslip());
zrequire('util');
zrequire('vdom');

run_test('basics', () => {
    const opts = {
        keyed_nodes: [],
        attrs: [
            ['class', 'foo'],
            ['title', 'cats & <"dogs">'],
        ],
    };

    const ul = vdom.ul(opts);

    const html = vdom.render_tag(ul);

    assert.equal(
        html,
        '<ul class="foo" title="cats &amp; &lt;&quot;dogs&quot;&gt;">\n\n' +
        '</ul>'
    );
});

run_test('attributes', () => {
    const opts = {
        keyed_nodes: [],
        attrs: [
            ['class', 'same'],
            ['color', 'blue'],
            ['id', '101'],
        ],
    };

    const ul = vdom.ul(opts);

    const html = vdom.render_tag(ul);

    assert.equal(
        html,
        '<ul class="same" color="blue" id="101">\n\n' +
        '</ul>'
    );

    let updated;
    let removed;

    function find() {<commit_msg>node tests: Add tests for escaped attributes in vdom.<commit_after>set_global('blueslip', global.make_zblueslip());
zrequire('util');
zrequire('vdom');

run_test('basics', () => {
    const opts = {
        keyed_nodes: [],
        attrs: [
            ['class', 'foo'],
            ['title', 'cats & <"dogs">'],
        ],
    };

    const ul = vdom.ul(opts);

    const html = vdom.render_tag(ul);

    assert.equal(
        html,
        '<ul class="foo" title="cats &amp; &lt;&quot;dogs&quot;&gt;">\n\n' +
        '</ul>'
    );
});

run_test('attribute escaping', () => {
    // So far most of the time our attributes are
    // hard-coded classes like "expanded_private_messages",
    // but we need to be defensive about future code
    // that might use data from possibly malicious users.
    const opts = {
        keyed_nodes: [],
        attrs: [
            ['class', '">something evil<div class="'],
            ['title', 'apples & oranges'],
        ],
    };

    const ul = vdom.ul(opts);

    const html = vdom.render_tag(ul);

    assert.equal(
        html,
        '<ul class="&quot;&gt;something evil&lt;div class=&quot;" ' +
        'title="apples &amp; oranges">\n\n</ul>'
    );
});

run_test('attribute updates', () => {
    const opts = {
        keyed_nodes: [],
        attrs: [
            ['class', 'same'],
            ['color', 'blue'],
            ['id', '101'],
        ],
    };

    const ul = vdom.ul(opts);

    const html = vdom.render_tag(ul);

    assert.equal(
        html,
        '<ul class="same" color="blue" id="101">\n\n' +
        '</ul>'
    );

    let updated;
    let removed;

    function find() {
{'fraction_non_alphanumeric': 0.19174382716049382, 'fraction_numerical': 0.004629629629629629, 'mean_word_length': 1.9770378874856487, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4491814', 'n_tokens_mistral': 886, 'n_tokens_neox': 853, 'n_words': 183}