libyuarel icon indicating copy to clipboard operation
libyuarel copied to clipboard

Bug in yuarel_parse_query() function

Open nike80 opened this issue 3 years ago • 3 comments

Hello, I found an error when 1 struct yuarel_param is passed to the yuarel_parse_query() function. They are not working properly.

		char* query = "a=b&c=d";
		yuarel_param params;
		yuarel_parse_query(query, '&', &params, 1);

		// HERE
		// params.key == "a"
		// params.val ==  "b&c=d"

nike80 avatar Nov 21 '22 06:11 nike80

try this:

char query[] = "a=b&c=d";
struct yuarel_param params[1];
ret=yuarel_parse_query(query, '&', params, 1);

7890 avatar May 09 '24 06:05 7890

This is actually because in https://github.com/jacketizer/libyuarel/blob/master/yuarel.c#L274 it only splits the & delimiter up to max_param times. To fix this issue we would need to do a clean up step where we run this one more time to check if there is additional & to at least null terminate.

That being said, the workaround is simply add at least +1 more to your max_param than your max expected param to overcome this issue.

mofosyne avatar Jan 27 '25 22:01 mofosyne

Okay made the fix in my fork under https://github.com/mofosyne/libyuarel/commit/75eb675f513c4f09bd0da6d6a96a01d7dd90208f

mofosyne avatar Jan 28 '25 12:01 mofosyne