forest's usability changes and fix html template encoding issue #1

Closed
forest wants to merge 3 commits from forest/reticule:main into main
Collaborator

https://stackoverflow.com/questions/17774958/go-after-parse-xml-file-with-template-parsefiles-the-first-became-lt
Go: After parse xml file with template.ParseFiles, the first "<" became "<"

This is how it looked before:

forest@thingpad:~$ curl -v http://localhost:8080/feed?key=EXAMPLE
*   Trying 127.0.0.1:8080...
...
< Content-Type: text/plain; charset=utf-8
< 
&lt;?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">

<channel>
	<title>test</title>

For some reason the html/template package is freakin out about <?xml ... and converting it to &lt;?xml for "safety" reasons. So I just removed that part from the template and output it directly.

https://stackoverflow.com/questions/17774958/go-after-parse-xml-file-with-template-parsefiles-the-first-became-lt Go: After parse xml file with template.ParseFiles, the first "<" became "&lt;" This is how it looked before: ``` forest@thingpad:~$ curl -v http://localhost:8080/feed?key=EXAMPLE * Trying 127.0.0.1:8080... ... < Content-Type: text/plain; charset=utf-8 < &lt;?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>test</title> ``` For some reason the `html/template` package is freakin out about `<?xml ...` and converting it to `&lt;?xml ` for "safety" reasons. So I just removed that part from the template and output it directly.
forest added 2 commits 2024-01-05 05:03:00 +00:00
forest reviewed 2024-01-05 05:08:15 +00:00
@ -16,3 +16,3 @@
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/go-shiori/dom v0.0.0-20230515143342-73569d674e1c // indirect
github.com/go-shiori/dom v0.0.0-20210627111528-4e4722cd0d65 // indirect
Author
Collaborator

I dont know why but I ran into module issues and the only way I was able to fix was by nuking my module cache, in the process I also tried deleting the transitive dependencies list and the go.sum file so thats why all these changes are here ☹️

I dont know why but I ran into module issues and the only way I was able to fix was by nuking my module cache, in the process I also tried deleting the transitive dependencies list and the `go.sum` file so thats why all these changes are here ☹️
Author
Collaborator

probably an issue unique to my environment but just thought I would explain what happened.

probably an issue unique to my environment but just thought I would explain what happened.
forest reviewed 2024-01-05 05:08:57 +00:00
@ -31,1 +31,4 @@
Body string `clover:"body"`
Added time.Time `clover:"added"`
Id string `clover:"_id"`
}
Author
Collaborator

auto formatter changes from vscodium

auto formatter changes from vscodium
forest reviewed 2024-01-05 05:09:22 +00:00
@ -53,3 +59,4 @@
conf.Init()
absPath, err := filepath.Abs(conf.DBPath)
Author
Collaborator

the data directory not existing tripped me up when I first tried to run it.

the data directory not existing tripped me up when I first tried to run it.
forest reviewed 2024-01-05 05:10:20 +00:00
@ -125,3 +144,3 @@
tplData.Articles = append(tplData.Articles, article)
}
tplData.Updated = tplData.Articles[0].Added
tplData.Updated = getFirstArticleAddedDate(tplData.Articles)
Author
Collaborator

This threw an unhandled exception when i 1st tried to run it:

forest@thingpad:~/Desktop/git/reticule$ go run . -db-path ./reticule-data -address 127.0.0.1 -port 8080 -api-key EXAMPLE  -feed-name test -feed-desc my-test-feed
[INFO] [cloverDB] creating database directory './reticule-data' (/home/forest/Desktop/git/reticule/reticule-data)
[INFO] Starting server on 127.0.0.1:8080
2024/01/04 22:15:41 http: panic serving 127.0.0.1:45624: runtime error: index out of range [0] with length 0
goroutine 18 [running]:
net/http.(*conn).serve.func1()
        /usr/local/go/src/net/http/server.go:1850 +0xbf
panic({0x9d8060, 0xc00039a150})
        /usr/local/go/src/runtime/panic.go:890 +0x262
main.main.func3({0xaf84e0, 0xc0003a40e0}, 0x4ca2d3?)
        /home/forest/Desktop/git/reticule/main.go:143 +0x448
net/http.HandlerFunc.ServeHTTP(0xc000123af0?, {0xaf84e0?, 0xc0003a40e0?}, 0x0?)
        /usr/local/go/src/net/http/server.go:2109 +0x2f
net/http.(*ServeMux).ServeHTTP(0xc00038008a?, {0xaf84e0, 0xc0003a40e0}, 0xc0003b8000)
        /usr/local/go/src/net/http/server.go:2487 +0x149
net/http.serverHandler.ServeHTTP({0xc00023bec0?}, {0xaf84e0, 0xc0003a40e0}, 0xc0003b8000)
        /usr/local/go/src/net/http/server.go:2947 +0x30c
net/http.(*conn).serve(0xc000388000, {0xaf8cc0, 0xc00023be60})
        /usr/local/go/src/net/http/server.go:1991 +0x607
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:3102 +0x4db
This threw an unhandled exception when i 1st tried to run it: ``` forest@thingpad:~/Desktop/git/reticule$ go run . -db-path ./reticule-data -address 127.0.0.1 -port 8080 -api-key EXAMPLE -feed-name test -feed-desc my-test-feed [INFO] [cloverDB] creating database directory './reticule-data' (/home/forest/Desktop/git/reticule/reticule-data) [INFO] Starting server on 127.0.0.1:8080 2024/01/04 22:15:41 http: panic serving 127.0.0.1:45624: runtime error: index out of range [0] with length 0 goroutine 18 [running]: net/http.(*conn).serve.func1() /usr/local/go/src/net/http/server.go:1850 +0xbf panic({0x9d8060, 0xc00039a150}) /usr/local/go/src/runtime/panic.go:890 +0x262 main.main.func3({0xaf84e0, 0xc0003a40e0}, 0x4ca2d3?) /home/forest/Desktop/git/reticule/main.go:143 +0x448 net/http.HandlerFunc.ServeHTTP(0xc000123af0?, {0xaf84e0?, 0xc0003a40e0?}, 0x0?) /usr/local/go/src/net/http/server.go:2109 +0x2f net/http.(*ServeMux).ServeHTTP(0xc00038008a?, {0xaf84e0, 0xc0003a40e0}, 0xc0003b8000) /usr/local/go/src/net/http/server.go:2487 +0x149 net/http.serverHandler.ServeHTTP({0xc00023bec0?}, {0xaf84e0, 0xc0003a40e0}, 0xc0003b8000) /usr/local/go/src/net/http/server.go:2947 +0x30c net/http.(*conn).serve(0xc000388000, {0xaf8cc0, 0xc00023be60}) /usr/local/go/src/net/http/server.go:1991 +0x607 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:3102 +0x4db ```
forest reviewed 2024-01-05 05:10:56 +00:00
@ -166,0 +193,4 @@
return time.Unix(0, 0)
}
func getTemplate(filename string) (*template.Template, error) {
Author
Collaborator

Honestly this function probably doesn't need to exist, I copy pasted it from greenhouse

Honestly this function probably doesn't need to exist, I copy pasted it from greenhouse
forest added 1 commit 2024-01-05 05:15:35 +00:00
Owner

https://stackoverflow.com/questions/17774958/go-after-parse-xml-file-with-template-parsefiles-the-first-became-lt
Go: After parse xml file with template.ParseFiles, the first "<" became "<"

This is how it looked before:

forest@thingpad:~$ curl -v http://localhost:8080/feed?key=EXAMPLE
*   Trying 127.0.0.1:8080...
...
< Content-Type: text/plain; charset=utf-8
< 
&lt;?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">

<channel>
	<title>test</title>

For some reason the html/template package is freakin out about <?xml ... and converting it to &lt;?xml for "safety" reasons. So I just removed that part from the template and output it directly.

in this case i think it might be better to just use text/template, no?

> https://stackoverflow.com/questions/17774958/go-after-parse-xml-file-with-template-parsefiles-the-first-became-lt > Go: After parse xml file with template.ParseFiles, the first "<" became "&lt;" > > This is how it looked before: > ``` > forest@thingpad:~$ curl -v http://localhost:8080/feed?key=EXAMPLE > * Trying 127.0.0.1:8080... > ... > < Content-Type: text/plain; charset=utf-8 > < > &lt;?xml version="1.0" encoding="UTF-8"?> > <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"> > > <channel> > <title>test</title> > > ``` > > For some reason the `html/template` package is freakin out about `<?xml ...` and converting it to `&lt;?xml ` for "safety" reasons. So I just removed that part from the template and output it directly. in this case i think it might be better to just use `text/template`, no?
Owner

ok i manually merged in some of your changes in f2afa6f1f6

i'm gonna try my idea for the template escaping issue and then i'll close this PR.

ok i manually merged in some of your changes in https://git.cyberia.club/reese/reticule/commit/f2afa6f1f66b52f6ba256ad0731e5865a71463a3 i'm gonna try my idea for the template escaping issue and then i'll close this PR.
Owner

...and here we go! this seems a bit cleaner to me

936023d710

...and here we go! this seems a bit cleaner to me https://git.cyberia.club/reese/reticule/commit/936023d7102f4837e817617bf0ea06d8ac4c0774
reese closed this pull request 2024-01-28 22:29:07 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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: reese/reticule#1
No description provided.