walle / wiki

Command line tool to fetch summaries from MediaWiki wikis, like Wikipedia
MIT License
290 stars 14 forks source link

Wrong output when using -n #14

Closed dkasak closed 5 years ago

dkasak commented 7 years ago

When the -n flag is used, the output has errors (stray %s format strings, coloured words repeated a few times, etc).

As an example, running:

wiki -n libressl

Results in the following output

Redirected from %s to %s

LibresslLibreSSLLibreSSL is an open-source implementation of the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols. It was forked from the OpenSSL cryptographic software library in April 2014 as a response by OpenBSD developers to the Heartbleed security vulnerability in OpenSSL, with the aim of refactoring the OpenSSL code so as to provide a more secure implementation.

LibreSSL was forked from the OpenSSL library starting with the 1.0.1g branch and will follow the security guidelines used elsewhere in the OpenBSD project.

Read more: %s
https://en.wikipedia.org/wiki/LibreSSL
jftuga commented 5 years ago

This fixes the problem by using fmt.Sprintf in wiki/cmd/wiki/main.go

138c138
<           fmt.Fprint(buf, "Redirected from %s to %s\n\n",
---
>           fmt.Fprint(buf, fmt.Sprintf("Redirected from %s to %s\n\n",
141c141
<           )
---
>           ))
144c144
<   fmt.Fprint(buf, "\nRead more: %s\n", page.URL)
---
>   fmt.Fprint(buf, fmt.Sprintf("\nRead more: %s\n", page.URL))