Skip to content

Disable url encodings in myhtml_attribute_add? #169

Open
@searene

Description

@searene

I want to disable the automatically applied URL encodings in myhtml_attribute_add. To be more specific, please check the following example:

#include <myhtml/api.h>

int main(int argc, const char * argv[])
{
    char html[] = "<img/>";

    // basic init
    myhtml_t* myhtml = myhtml_create();
    myhtml_init(myhtml, MyHTML_OPTIONS_DEFAULT, 1, 0);

    // init tree
    myhtml_tree_t* tree = myhtml_tree_create();
    myhtml_tree_init(tree, myhtml);

    // parse html
    myhtml_parse_fragment(tree, MyENCODING_UTF_8, html, strlen(html), MyHTML_TAG_DIV, MyHTML_NAMESPACE_HTML);

    // get first img from index
    myhtml_collection_t *div_list = myhtml_get_nodes_by_name(tree, NULL, "img", 3, NULL);
    myhtml_tree_node_t *node = div_list->list[0];

    // add an attr
    const char* srcValue = "custom_protocol://resource?id=1&name=apple";
    myhtml_attribute_add(node, "src", 3, srcValue, strlen(srcValue), MyENCODING_UTF_8);

    mycore_string_raw_t str = {0};
    myhtml_serialization_tree_buffer(myhtml_tree_get_document(tree), &str);
    printf("%s", str.data);

    // release resources
    myhtml_collection_destroy(div_list);
    myhtml_tree_destroy(tree);
    myhtml_destroy(myhtml);

    return 0;
}

The output is as follows:

<html><img src="custom_protocol://resource?id=1&amp;name=apple"></img></html>

As you can see, the & between id=1 and name=apple was automatically URL-encoded, which is not what I want. I want it to be the same as the one passed by me, in other words, I want the following result:

<html><img src="custom_protocol://resource?id=1&name=apple"></img></html>

Is there anyway to do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions