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

Add g_markup_escape_text to Glib #832

Merged
merged 1 commit into from
Sep 10, 2021
Merged

Add g_markup_escape_text to Glib #832

merged 1 commit into from
Sep 10, 2021

Conversation

olabiniV2
Copy link

No description provided.

@sqp
Copy link
Member

sqp commented Sep 10, 2021

Hey, yes unvalidated input has to be escaped before applying tags to use in gtk. (I'm applying the bold tag to the important parts I'm aware of for those who don't know that problem)

Here's what I'm using that seemed enough for now.

// Escape escapes a string to use as gtk text: &<>.
//
func Escape(msg string) string {
	msg = strings.Replace(msg, "&", "&amp;", -1) // Escape ampersand.
	msg = strings.Replace(msg, "<", "&lt;", -1)  // Escape <.
	msg = strings.Replace(msg, ">", "&gt;", -1)  // Escape >.
	return msg
}

If I have any issue with this some day, I might take the time to check the source to see what's more to do and complete it.

But that would be nice to make a complete go version if someone finds the motivation.

@sqp sqp merged commit bae3fb6 into gotk3:master Sep 10, 2021
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.

None yet

3 participants