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

ansi escapes in custom source markers #12435

Merged
merged 6 commits into from
Jan 6, 2023
Merged

Conversation

romainfrancois
Copy link
Contributor

@romainfrancois romainfrancois commented Dec 14, 2022

Intent

addresses #12425

Approach

Avoid to create an AceAnnotation with both .text and .html because otherwise .text is prefered as per this code in ace:

var annoText = annotation.text;
annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || "";

Alternatively, the ace code could use annotation.html ? instead of annotation.text ? so that the html version would have priority.

Automated Tests

Indicate whether this change includes unit tests or integration tests, or link a work item or pull request to add those tests to another repo. If the change cannot or will not be covered by a test, indicate why.

QA Notes

Save this file as test.R in the current working directory:

tmpfile <- "test.R"

foo <- cli::bg_br_white(cli::col_red("I am red!"))
bar <- cli::bg_br_yellow(cli::col_cyan("I am cyan!"))

markers <- list(
  list(
    type = "error",
    file = tmpfile,
    line = 6,
    column = 1,
    message = structure("<i>I am Groot</i>", class = "html")
  ),
  list(
    type = "info", 
    file = tmpfile,
    line = 12,
    column = 1,
    message = bar))

.rs.api.sourceMarkers("Test Name", markers)

and then run it.

Expected:

Markers tab:

image

Annotations:

image

image

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

@romainfrancois
Copy link
Contributor Author

cc @timtmok or should the structure(class = "html") path be removed ? e.g. this would need I believe some tweaks around:

"messageHTML", messageHTML);

to entirely avoid already structured html, and the risks of js injection it brings.

@romainfrancois
Copy link
Contributor Author

Related to #12048, an orthogonal follow up could be to support annotations to carry an html widget. This would be safer as they are wrapped around an <iframe>

@romainfrancois
Copy link
Contributor Author

TODO: this breaks the source markers:

Enregistrement.de.l.ecran.2022-12-14.a.13.42.26.mov

@romainfrancois romainfrancois marked this pull request as draft December 14, 2022 12:44
@romainfrancois romainfrancois marked this pull request as ready for review December 14, 2022 13:35
Copy link
Contributor

@timtmok timtmok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@romainfrancois
Copy link
Contributor Author

Following up on #10278 I think we have to give up on the structure(, class = "html") because e.g. we could have message = structure('<i onclick = "alert(42)">I am Groot</i>', class = "html") which does alert() :

image

@romainfrancois
Copy link
Contributor Author

Disabled it so that custom source markers can't emit already prepared html content:

tmpfile <- "test.R"

foo <- cli::bg_br_white(cli::col_red("I am red!"))
bar <- cli::bg_br_yellow(cli::col_cyan("I am cyan!"))

markers <- list(
  list(
    type = "error",
    file = tmpfile,
    line = 6,
    column = 1,
    message = structure('<i onclick = "alert(42)">I am Groot</i>', class = "html")
  ),
  list(
    type = "info", 
    file = tmpfile,
    line = 12,
    column = 1,
    message = bar))

.rs.api.sourceMarkers("Test Name", markers)

gives:

image

image

markers that we make internally may be html, but I don't think this is used at the moment.

We can consider a followup where we would allow creating markers/annotations that would consist of some html widget, that we could embed as an <iframe> so be less risky.

@romainfrancois romainfrancois merged commit c78e9d4 into main Jan 6, 2023
@romainfrancois romainfrancois deleted the fix/source_markers_ansi branch January 6, 2023 11:26
MariaSemple pushed a commit that referenced this pull request Jan 9, 2023
* make .rs.scalar() after extrating `html`ness

* AceAnnotation.html()

* rework LintItem.asAceAnnotations() so that they either have html or text

* LintItem may have html or text, not raw

* handle AceAnnotation.html

* don't treat `class = "html"` in custom source markers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants