Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

& escaped as &#xamp; instead of & in links to URLs with query strings #24

Open
AnyOldName3 opened this issue Jan 17, 2024 · 1 comment

Comments

@AnyOldName3
Copy link

This is a regression since the upstream 3.49.2 release that Windows binaries are provided for - that would write &. I've not been able to determine when the regression was introduced as it wasn't obvious from the diffs for individual commits or overall diff, and C and French aren't my usual languages.

This isn't just a stylistic problem - &#xamp; isn't valid HTML, and doesn't produce an ampersand. The things that do are &, & and &.

This is a before and after for a website first done with upstream 3.49.2, and redone with the master branch of this fork:

image

In regular text, ampersands are left alone with the escaping (or lack thereof) they had originally, so it seems to be something related to how URLs are extracted and replaced.

@AnyOldName3
Copy link
Author

Looks like it was #10, and the new escaping function added by that MR never worked properly. This change fixes it:

diff --git a/src/htslib.c b/src/htslib.c
index e900a3c..a17c1af 100644
--- a/src/htslib.c
+++ b/src/htslib.c
@@ -3914,8 +3914,10 @@ HTSEXT_API size_t x_escape_flags(const char* const s, char* const dest, const si
 		} else {
 			if (flags & ENCODE_PARAMS_AS_HTML_ENTITIES) {
 				ADD_CHAR('&');
-				ADD_CHAR('#');
-				ADD_CHAR('x');
+				if (c != '&') {
+					ADD_CHAR('#');
+					ADD_CHAR('x');
+				}
 			} else
 				ADD_CHAR('%');
 			if (c != '&' || (flags & ENCODE_PARAMS_AS_HTML_ENTITIES) == FALSE) {

This might not apply cleanly as I'd monkey-patched something else in the same file, so the line numbers won't match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant