Skip to content

Commit

Permalink
(fix) (de)serialization issues with custom tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvandenberg committed Dec 9, 2023
1 parent bfbbef6 commit 16fda46
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 7 deletions.
Binary file modified build/Release/tree_sitter_angular_binding.node
Binary file not shown.
35 changes: 35 additions & 0 deletions corpus/selectors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
==================
Component selector
==================

<a-button>Label</a-button>

---

(fragment
(element
(start_tag
(tag_name)
)
(text)
(end_tag
(tag_name)
)
)
)

=====================
Self closing selector
=====================

<a-button />

---

(fragment
(element
(self_closing_tag
(tag_name)
)
)
)
5 changes: 2 additions & 3 deletions corpus/structural-directives.txt
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,8 @@ Template Outlet context
)
)
)
(erroneous_end_tag
(erroneous_end_tag_name)
(end_tag
(tag_name)
)
(MISSING _implicit_end_tag)
)
)
Empty file added src/html.scanner.c
Empty file.
Empty file added src/html.tag.h
Empty file.
10 changes: 7 additions & 3 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ static unsigned serialize(Scanner *scanner, char *buffer) {
if (size + 2 + name_length >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) {
break;
}
buffer[size++] = (char)tag.type;
buffer[size++] = (char)name_length;
buffer[size++] =
(unsigned char)tag.type; // <-- This is because otherwise it is read
// as a negative value
buffer[size++] = (unsigned char)name_length;
strncpy(&buffer[size], tag.custom_tag_name.data, name_length);
size += name_length;
} else {
Expand Down Expand Up @@ -165,7 +167,9 @@ static void deserialize(Scanner *scanner, const char *buffer, unsigned length) {
unsigned iter = 0;
for (iter = 0; iter < serialized_tag_count; iter++) {
Tag tag = scanner->tags.data[iter];
tag.type = (TagType)buffer[size++];
tag.type =
(unsigned char)buffer[size++]; // <-- This is because otherwise it
// is read as a negative value
if (tag.type == CUSTOM) {
uint16_t name_length = (uint8_t)buffer[size++];
tag.custom_tag_name.len = name_length;
Expand Down
2 changes: 1 addition & 1 deletion src/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ typedef struct {
String custom_tag_name;
} Tag;

const TagMap TAG_TYPES_BY_TAG_NAME[128] = {
const TagMap TAG_TYPES_BY_TAG_NAME[126] = {
{"AREA", AREA},
{"BASE", BASE},
{"BASEFONT", BASEFONT},
Expand Down
Empty file added src/tree_sitter/html.parser.h
Empty file.

0 comments on commit 16fda46

Please sign in to comment.