byteface / domonic

Create HTML with python 3 using a standard DOM API. Includes a python port of JavaScript for interoperability and tons of other cool features. A fast prototyping library.
https://domonic.readthedocs.io/
MIT License
128 stars 13 forks source link

bug with rendering urls in <a> tags #9

Closed wmacmillan closed 3 years ago

wmacmillan commented 3 years ago

Howdy. There seems to be some issue rendering the href tag, at least in <a> tags. If you include query parameters it cuts off the link past the ?, if you include https://. See below.

Note, the link does work if put into resulting html correctly (meaning, with the query).

from domonic import a, render

if __name__ == "__main__":

    urls = [
      'example.com/stuff?things=morestuff',
      'https://example.com/stuff?things=morestuff',
      'https://example.com/stuff',
      'https://www.example.com/stuff?thing',
      'https://www.example.com/?stuff'
    ]

    for url in urls:
        print(
            f'''
---------
Renders as: {render(a(_href=url))}
 should be: <a href="{url}"></a>
---------'''
        )

results in the following:

---------
Renders as: <a href="example.com/stuff?things=morestuff"></a>
 should be: <a href="example.com/stuff?things=morestuff"></a>
---------

---------
Renders as: <a href="https://example.com/stuff"></a>
 should be: <a href="https://example.com/stuff?things=morestuff"></a>
---------

---------
Renders as: <a href="https://example.com/stuff"></a>
 should be: <a href="https://example.com/stuff?thing"></a>
---------

---------
Renders as: <a href="https://www.example.com/stuff"></a>
 should be: <a href="https://www.example.com/stuff?thing"></a>
---------

---------
Renders as: <a href="https://www.example.com/"></a>
 should be: <a href="https://www.example.com/?stuff"></a>
---------
byteface commented 3 years ago

very sorry. query params has been on my mind a while for this tag. (i kinda supsected this might happen) i recently did URLSearchParams so hopefully can fix this up asap. thanks so much for reporting it.

byteface commented 3 years ago

thank you so much. this is now fixed in 0.3.16 and I've added your code to the unit test with assertions.

python -m unittest tests.test_html.domonicTestCase.test_domonic_render_a_tag_query_params

wmacmillan commented 3 years ago

Thank you for the useful code! Happy to contribute.