[GH-ISSUE #234] Escaping in the TextView seems faulty #180

Closed
opened 2026-03-04 01:02:41 +03:00 by kerem · 4 comments
Owner

Originally created by @Bios-Marcel on GitHub (Feb 5, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/234

Hey,

I am currently writing a chat application, that means the textview can get filled with arbitrary text.

I just had a user write a small snippet of code:

`{["print"] = print}`

It was basically a line of code with markdown around it. After calling tview.Escape, it renders the text like this:

`{ 

I assume this is a bug, or did I missunderstand tview.Escape?

Originally created by @Bios-Marcel on GitHub (Feb 5, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/234 Hey, I am currently writing a chat application, that means the textview can get filled with arbitrary text. I just had a user write a small snippet of code: ```md `{["print"] = print}` ``` It was basically a line of code with markdown around it. After calling `tview.Escape`, it renders the text like this: ``` `{ ``` I assume this is a bug, or did I missunderstand `tview.Escape`?
kerem closed this issue 2026-03-04 01:02:41 +03:00
Author
Owner

@Bios-Marcel commented on GitHub (Feb 7, 2019):

Can be reproduced using this:

package main

import "github.com/rivo/tview"

func main() {
	textView := tview.NewTextView()
	textView.SetDynamicColors(true)
	textView.SetRegions(true)
	textView.SetText(tview.Escape("`{[\"print\"] = print}`"))

	app := tview.NewApplication()
	app.SetRoot(textView, true)
	app.Run()
}

It works fine when either Regions or DynamicColors are set to false, however, when both are true it causes problems.

I think this could be added as a recursion unit test after fixing this:

package tests

import (
	"testing"

	"github.com/rivo/tview"
)

func TestEscapeBug234(t *testing.T) {
	input := "`{[\"print\"] = print}`"
	textView := tview.NewTextView()
	textView.SetDynamicColors(true)
	textView.SetRegions(true)

	escapedString := tview.Escape(input)
	textView.SetText("[\"all\"]" + escapedString + "[\"\"]")
	textFromTextView := textView.GetRegionText("all")

	if textFromTextView != input {
		t.Errorf("Was '%s', but should have been: '%s'.", textFromTextView, input)
	}
}
<!-- gh-comment-id:461377609 --> @Bios-Marcel commented on GitHub (Feb 7, 2019): Can be reproduced using this: ```go package main import "github.com/rivo/tview" func main() { textView := tview.NewTextView() textView.SetDynamicColors(true) textView.SetRegions(true) textView.SetText(tview.Escape("`{[\"print\"] = print}`")) app := tview.NewApplication() app.SetRoot(textView, true) app.Run() } ``` It works fine when either `Regions` or `DynamicColors` are set to `false`, however, when both are `true` it causes problems. I think this could be added as a recursion unit test after fixing this: ```go package tests import ( "testing" "github.com/rivo/tview" ) func TestEscapeBug234(t *testing.T) { input := "`{[\"print\"] = print}`" textView := tview.NewTextView() textView.SetDynamicColors(true) textView.SetRegions(true) escapedString := tview.Escape(input) textView.SetText("[\"all\"]" + escapedString + "[\"\"]") textFromTextView := textView.GetRegionText("all") if textFromTextView != input { t.Errorf("Was '%s', but should have been: '%s'.", textFromTextView, input) } } ```
Author
Owner

@rivo commented on GitHub (Feb 13, 2019):

Thank you for catching this. I believe I fixed this with the latest commit. Let me know in case you still find anything here.

<!-- gh-comment-id:463233846 --> @rivo commented on GitHub (Feb 13, 2019): Thank you for catching this. I believe I fixed this with the latest commit. Let me know in case you still find anything here.
Author
Owner

@Bios-Marcel commented on GitHub (Feb 13, 2019):

Cool, seems to be working fine. Anyhow, what do you think about regression tests? I think it'd be cool to prevent such bugs from happening again. Stuff like parsing logic and such is always quite fragile in my opinion.

<!-- gh-comment-id:463237748 --> @Bios-Marcel commented on GitHub (Feb 13, 2019): Cool, seems to be working fine. Anyhow, what do you think about regression tests? I think it'd be cool to prevent such bugs from happening again. Stuff like parsing logic and such is always quite fragile in my opinion.
Author
Owner

@rivo commented on GitHub (Feb 13, 2019):

Yeah, it's on my list. What I would like to have in there is a test stub for tcell.Screen whose character buffer could then be checked against in the test cases. So it wouldn't just be parsing logic but also layouts and user input behaviour that could be tested this way.

Haven't had time for this yet, though.

<!-- gh-comment-id:463267194 --> @rivo commented on GitHub (Feb 13, 2019): Yeah, it's on my list. What I would like to have in there is a test stub for [`tcell.Screen`](https://godoc.org/github.com/gdamore/tcell#Screen) whose character buffer could then be checked against in the test cases. So it wouldn't just be parsing logic but also layouts and user input behaviour that could be tested this way. Haven't had time for this yet, though.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#180
No description provided.