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

panic: strings: negative Repeat count #103

Closed
sheeeng opened this issue Oct 24, 2024 · 3 comments
Closed

panic: strings: negative Repeat count #103

sheeeng opened this issue Oct 24, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@sheeeng
Copy link

sheeeng commented Oct 24, 2024

Problem Statement

$ xq --version
xq version 1.2.5 (2024-08-29T13:50:34Z, fb8ac87a3431cdfebeeda81053562e3aeebde6af)

Got error message from following command.

Steps to Reproduce

curl --silent https://api.politiet.no/politiloggen/v1/rss | xq --html

Actual Result

<?xml version="1.0" encoding="utf-16"?>
panic: strings: negative Repeat count

goroutine 7 [running]:
strings.Repeat({0x1030c0426?, 0x140000584e0?}, 0x140000a0de0?)
        strings/strings.go:569 +0x588
github.com/sibprogrammer/xq/internal/utils.FormatHtml({0x1031dc988?, 0x1400007e080?}, {0x1031dca48, 0x140000584e0}, {0x1030c0426, 0x2}, 0x0)
        github.com/sibprogrammer/xq/internal/utils/utils.go:387 +0x680
github.com/sibprogrammer/xq/cmd.init.NewRootCmd.func1.1()
        github.com/sibprogrammer/xq/cmd/root.go:82 +0x224
created by github.com/sibprogrammer/xq/cmd.init.NewRootCmd.func1 in goroutine 1
        github.com/sibprogrammer/xq/cmd/root.go:67 +0x33c
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
...
...

Expected Result

<?xml version="1.0" encoding="utf-16"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
...
...
@sheeeng sheeeng added the bug Something isn't working label Oct 24, 2024
@sibprogrammer
Copy link
Owner

The option --html assumes the input in HTML format. It fails in this case because of link tag which doesn't assume content in the HTML context.
RSS format is an XML and no additional options are required. But xq is fooled by the utf-16 encoding declaration and produces gibberish in this example. In fact, xq has no true UTF-16 support and I probably can workaround this particular problem by UTF-8 enforcement.

@SharonBrizinov
Copy link

SharonBrizinov commented Oct 26, 2024

@sibprogrammer
Thanks for building xq, it's a great utility and I find it very useful!

I didn't want to open a new issue so I'm adding a bit more information here as I'm getting a similar crash for even simpler cases, for example on Mac OSX (xq version 1.2.5 (2024-08-29T13:50:34Z, fb8ac87a3431cdfebeeda81053562e3aeebde6af)):

echo '<!doctype html><a></a></html>' | xq

results with -

panic: strings: negative Repeat count

goroutine 19 [running]:
strings.Repeat({0x3a0d48e?, 0xc0001303c0?}, 0xc000118dd8?)
        strings/strings.go:569 +0x56b
github.com/sibprogrammer/xq/internal/utils.FormatHtml({0x3b27aa8?, 0xc000094000?}, {0x3b27a68, 0xc0001303c0}, {0x3a0d48e, 0x2}, 0x0)
        github.com/sibprogrammer/xq/internal/utils/utils.go:387 +0x84d
github.com/sibprogrammer/xq/cmd.init.NewRootCmd.func1.1()
        github.com/sibprogrammer/xq/cmd/root.go:82 +0x2b9
created by github.com/sibprogrammer/xq/cmd.init.NewRootCmd.func1 in goroutine 1
        github.com/sibprogrammer/xq/cmd/root.go:67 +0x3ca

I did notice that on a Linux machine I need to specify --html to reach similar results

echo '<!doctype html><a></a></html>' | xq --html

@sibprogrammer
Copy link
Owner

@SharonBrizinov The root cause of the problem in the initial comment was a little bit different. For your use case, it's an attempt to format invalid XML and HTML. Unfortunately, xq crashed instead of trying to get the best possible output. The utility definitely will not provide nice-looking XML because the source is invalid, but I will try to handle the errors at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants