Himujjal / tree-sitter-svelte

Tree sitter grammar for Svelte
MIT License
77 stars 15 forks source link

Take the absolute value of tag type before casting #29

Closed aral closed 2 years ago

aral commented 2 years ago

In my fork I added a GET element/tag (which includes JavaScript code that’s executed on the server) and this caused some of the other tests to fail.

Looking into the issue, I was able to narrow it down to the compareTags() call in the scan_end_tag_name in src/scanner.c failing and resulting in ERRORNEOUS_END_TAG_NAME errors whenever a custom tag was encounter. Looking deeper, I saw that the comparison of a->type and b->type in compareTags was failing with -128 != 128. Given TagType should be unsigned, I started wondering where a negative value could have crept in and looked for any casts that might be happening, which led me to the one in the vc_vector_resize() function in this pull request.

Taking the absolute value of the value in the buffer before casting it seems to have solved the issue and all my tests are passing again.

This doesn’t affect the tree-sitter-svelte codebase as it stands currently but it should arise if you were to add another tag to TagType in the future.

Himujjal commented 2 years ago

Thank you for the pull request. I never faced any problems with the current state of the code. This is a really good addition to the library. It will definitely solve many issues with the library as it stands