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

Fixed a bug where ampersand character (&) was escaped in Child operators #175

Merged
merged 1 commit into from
May 23, 2024

Conversation

rjgpacheco
Copy link
Contributor

@rjgpacheco rjgpacheco commented May 23, 2024

This PR fixes what seems to be a bug in the string serialisation for expressions.

The ampersand & character got escaped into \h which, besides not being the right string, also isn't a valid according to jp.ParseString, eg (https://go.dev/play/p/BDjHacoE4Hu):

package main

import (
	"fmt"
	"github.com/ohler55/ojg/jp"
)

func main() {
	original := jp.R().C("a & b")
	_, err := jp.ParseString(original.BracketString())
	fmt.Println(err)
}

Shows the error:

0x68 (h) is not a valid escaped character

I've added some basic tests covering this, but I'm unfamiliar with other parts of the code. I think the only place this is relevant is in

ojg/string.go

Lines 61 to 69 in aede9ec

case 'h':
if htmlSafe {
if start < i {
buf = append(buf, s[start:i]...)
}
buf = append(buf, `\u00`...)
buf = append(buf, hex[(b>>4)&0x0f])
buf = append(buf, hex[b&0x0f])
start = i + 1
, where it seems to be parting HTML, where & is special. I think the mapping got copied over and this bug sneaked in.

@ohler55
Copy link
Owner

ohler55 commented May 23, 2024

Great catch and fix. Thank you.

@ohler55 ohler55 merged commit 7a61575 into ohler55:develop May 23, 2024
3 checks passed
@rjgpacheco rjgpacheco deleted the rpacheco/fix-ampersand branch May 24, 2024 11:52
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

Successfully merging this pull request may close these issues.

2 participants