Coder Social home page Coder Social logo

Support for ansi terminal links about ansi_up HOT 16 CLOSED

drudru avatar drudru commented on July 30, 2024
Support for ansi terminal links

from ansi_up.

Comments (16)

drudru avatar drudru commented on July 30, 2024 2

Ok - pushed out the npm release. Thanks to all for your help.

from ansi_up.

drudru avatar drudru commented on July 30, 2024 1

This is awesome!

I'm happy to add support for this. In progress...

👍

from ansi_up.

drudru avatar drudru commented on July 30, 2024 1

Hi - quick update. Made some good progress over the last few days. More soon.

from ansi_up.

drudru avatar drudru commented on July 30, 2024 1

@LaKing - ok - code for testing is up on master. It required a lot of changes, but we were due for that anyways 👍

I will be cleaning it up and revising the Readme tomorrow.
The big difference is that there is only ansi_to_html now.

Lmk if you have any comments on the functionality.

from ansi_up.

LaKing avatar LaKing commented on July 30, 2024 1

One more thing.

The URL part seems to rely on the protocol prefix, eg. http or https, thus relative links for example are not parsed, but left out empty. (no html at all)

from ansi_up.

drudru avatar drudru commented on July 30, 2024 1

@alech - thx, will investigate

from ansi_up.

drudru avatar drudru commented on July 30, 2024 1

@alech - ok, have time this week to work on all these issues. Updates soon.

from ansi_up.

drudru avatar drudru commented on July 30, 2024

Hi - I am not aware of this new tagging feature. Can you point me at where this is documented?
Which terminals support this?

If this is a new convention, that is great news. We could bring back the linkify code.

from ansi_up.

LaKing avatar LaKing commented on July 30, 2024

The best documentation found so far is this.

I'm using GNOME on Fedora, and I can confirm both of the above examples work.

JS example to create terminal links:
terminal-link (listed also on the bottom of chalk)
Sample is index.js from
hyperlinker

from ansi_up.

drudru avatar drudru commented on July 30, 2024

Just an update. This is going to require a bit of work. However, that is ok. Now is a good time to clean up other parts as well.

from ansi_up.

LaKing avatar LaKing commented on July 30, 2024

Great!

This is my library of choice .) ...
.. let me know if I can help!

from ansi_up.

LaKing avatar LaKing commented on July 30, 2024

Works great!

Updated my code, and found no issues so far.

Thank you very much!

The only thing left is an update on the readme, and publishing it to npm. .)

from ansi_up.

LaKing avatar LaKing commented on July 30, 2024

Oopps, .. It works for the node way of creating links, but the bash way seems to left untouched as text.

from ansi_up.

LaKing avatar LaKing commented on July 30, 2024

Okay, I found a bug I think.

If the text part has a space, it breaks.

Problematic code "link 12" with a space

^[[34m^[]8;;http://example.com^Glink 12^[]8;;^G^[[0m

Working code "link:12" with no spaces

^[[34m^[]8;;http://example.com^Glink:12^[]8;;^G^[[0m

Both of these work in the terminal, but the problematic html output is

<span>]8;;http://example.com�link 12</span><span>]8;;�</span>

By the way, the alternative bash code for writing links similar way as the node code does (with \a)

## standard
echo -e '\e]8;;http://example.com\aThis is a link\e]8;;\a'
## colored
echo -e '\e[34m\e]8;;http://example.com\aThis is a link\e]8;;\a\e[0m' 

from ansi_up.

alech avatar alech commented on July 30, 2024

The current implementation is prone to a DOM-based XSS attack. Since the URL parameter allows \x21-\x7e characters and the URL gets inserted into href attribute without filtering, an attacker can close the a tag and add (nearly) arbitrary HTML into the return value of process_hyperlink. I would suggest actually parsing the URL with new URL and then using the href attribute of the result in order to be safe (plus the filtering of the schemes which is already in place and is a good feature could then be made more robust).

PoC:

    var txt = ' \x1b]8;;http://example.com"></a><img/src="foo"onerror=alert(1)><pp\x1b\\.\x1b]8;;\x1b\\ ';

    var ansi_up = new AnsiUp;
    var html = ansi_up.ansi_to_html(txt);
    var cdiv = document.getElementById("console");
    cdiv.innerHTML = html;

from ansi_up.

drudru avatar drudru commented on July 30, 2024

I'm keeping this issue open for a few more days. Once I push the NPM, then I will close the issue.

from ansi_up.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.