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

[Bug]: Failing test UTF characters are replaced differently #629

Closed
3 tasks done
llrs-roche opened this issue Nov 8, 2024 · 5 comments
Closed
3 tasks done

[Bug]: Failing test UTF characters are replaced differently #629

llrs-roche opened this issue Nov 8, 2024 · 5 comments
Labels
bug Something isn't working core

Comments

@llrs-roche
Copy link
Contributor

What happened?

While testing for #623 I found this issue:

devtools::load_all(".")
testthat::test_file("tests/testthat/test-utils.R")
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 9 ]

── Failure (test-utils.R:87:5): should replace UTF characters outside the allowed range ──
teal.slice:::NS("app", id) not identical to paste0("app-h", substr(rlang::hash(id), 1, 4), "_A_0_z_").
1/1 mismatches
x[1]: "app-h1724_A_0_z__"
y[1]: "app-h1724_A_0_z_"
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 9 ]

I thought this could be related to my locale but I changed the Sys.setlocale(locale = "C") and it persisted.
The code has changed recently (last month):

testthat::it("should replace UTF characters outside the allowed range", {
id <- "\U41\U05E\U30\U5F\U7A\U1F4AA" # "A:circumflex_accent:0_z:flexed_biceps:
testthat::expect_identical(
teal.slice:::NS("app", id),
paste0(
"app-h",
substr(rlang::hash(id), 1, 4),
"_A_0_z_"
)
)
})

sessionInfo()

Session info ────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.1 (2024-06-14 ucrt)
 os       Windows 11 x64 (build 22631)
 system   x86_64, mingw32
 ui       RStudio
 language en
 collate  Spanish_Spain.utf8
 ctype    Spanish_Spain.utf8
 tz       Europe/Madrid
 date     2024-11-08
 rstudio  2024.09.0+375 Cranberry Hibiscus (desktop)
 pandoc   3.5 @ C:\\Users\\sanchosl\\AppData\\Local\\Pandoc\\pandoc.exePackages ────────────────────────────────────────────────────────────────────
 !  package         * version    date (UTC) lib source
    backports         1.5.0      2024-05-23 [1] CRAN (R 4.4.0)
    brio              1.1.5      2024-04-24 [1] CRAN (R 4.4.1)
    bslib             0.8.0      2024-07-29 [1] CRAN (R 4.4.1)
    cachem            1.1.0      2024-05-16 [1] CRAN (R 4.4.1)
    checkmate         2.3.2      2024-07-29 [1] CRAN (R 4.4.1)
    cli               3.6.3      2024-06-21 [1] CRAN (R 4.4.1)
    colorspace        2.1-1      2024-07-26 [1] CRAN (R 4.4.1)
    data.table        1.16.2     2024-10-10 [1] CRAN (R 4.4.1)
    desc              1.4.3      2023-12-10 [1] CRAN (R 4.4.1)
    devtools        * 2.4.5      2022-10-11 [1] CRAN (R 4.4.1)
    digest            0.6.37     2024-08-19 [1] CRAN (R 4.4.1)
    dplyr             1.1.4      2023-11-17 [1] CRAN (R 4.4.1)
    ellipsis          0.3.2      2021-04-29 [1] CRAN (R 4.4.1)
    fansi             1.0.6      2023-12-08 [1] CRAN (R 4.4.1)
    fastmap           1.2.0      2024-05-15 [1] CRAN (R 4.4.1)
    fs                1.6.5      2024-10-30 [1] CRAN (R 4.4.1)
    generics          0.1.3      2022-07-05 [1] CRAN (R 4.4.1)
    ggplot2           3.5.1      2024-04-23 [1] CRAN (R 4.4.1)
    glue              1.8.0      2024-09-30 [1] CRAN (R 4.4.1)
    gtable            0.3.6      2024-10-25 [1] CRAN (R 4.4.1)
    htmltools         0.5.8.1    2024-04-04 [1] CRAN (R 4.4.1)
    htmlwidgets       1.6.4      2023-12-06 [1] CRAN (R 4.4.1)
    httpuv            1.6.15     2024-03-26 [1] CRAN (R 4.4.1)
    httr              1.4.7      2023-08-15 [1] CRAN (R 4.4.1)
    jquerylib         0.1.4      2021-04-26 [1] CRAN (R 4.4.1)
    jsonlite          1.8.9      2024-09-20 [1] CRAN (R 4.4.1)
    later             1.3.2      2023-12-06 [1] CRAN (R 4.4.1)
    lazyeval          0.2.2      2019-03-15 [1] CRAN (R 4.4.1)
    lifecycle         1.0.4      2023-11-07 [1] CRAN (R 4.4.1)
    logger            0.4.0      2024-10-22 [1] CRAN (R 4.4.1)
    magrittr          2.0.3      2022-03-30 [1] CRAN (R 4.4.1)
    memoise           2.0.1      2021-11-26 [1] CRAN (R 4.4.1)
    mime              0.12       2021-09-28 [1] CRAN (R 4.4.0)
    miniUI            0.1.1.1    2018-05-18 [1] CRAN (R 4.4.1)
    munsell           0.5.1      2024-04-01 [1] CRAN (R 4.4.1)
    pillar            1.9.0      2023-03-22 [1] CRAN (R 4.4.1)
    pkgbuild          1.4.5      2024-10-28 [1] CRAN (R 4.4.1)
    pkgconfig         2.0.3      2019-09-22 [1] CRAN (R 4.4.1)
    pkgdown         * 2.1.1      2024-09-17 [1] CRAN (R 4.4.1)
    pkgload           1.4.0      2024-06-28 [1] CRAN (R 4.4.1)
    plotly            4.10.4     2024-01-13 [1] CRAN (R 4.4.1)
    profvis           0.4.0      2024-09-20 [1] CRAN (R 4.4.1)
    promises          1.3.0      2024-04-05 [1] CRAN (R 4.4.1)
    prompt            1.0.2      2023-08-31 [1] CRAN (R 4.4.1)
    purrr             1.0.2      2023-08-10 [1] CRAN (R 4.4.1)
    R6                2.5.1      2021-08-19 [1] CRAN (R 4.4.1)
    Rcpp              1.0.13-1   2024-11-02 [1] CRAN (R 4.4.1)
    remotes           2.5.0      2024-03-17 [1] CRAN (R 4.4.1)
    rlang             1.1.4      2024-06-04 [1] CRAN (R 4.4.1)
    rprojroot         2.0.4      2023-11-05 [1] CRAN (R 4.4.1)
    rstudioapi        0.17.1     2024-10-22 [1] CRAN (R 4.4.1)
    sass              0.4.9      2024-03-15 [1] CRAN (R 4.4.1)
    scales            1.3.0      2023-11-28 [1] CRAN (R 4.4.1)
    sessioninfo       1.2.2      2021-12-06 [1] CRAN (R 4.4.1)
    shiny             1.9.1      2024-08-01 [1] CRAN (R 4.4.1)
    shinycssloaders   1.1.0      2024-07-30 [1] CRAN (R 4.4.1)
    shinyjs           2.1.0      2021-12-23 [1] CRAN (R 4.4.1)
    shinyWidgets      0.8.7      2024-09-23 [1] CRAN (R 4.4.1)
    teal.code         0.5.0.9013 2024-11-08 [1] local
    teal.data         0.6.0.9016 2024-11-08 [1] local
    teal.logger       0.3.0      2024-10-24 [1] CRAN (R 4.4.1)
 VP teal.slice      * 0.5.1.9015 2024-10-21 [?] Github (insightsengineering/teal.slice@aa05f7f) (on disk 0.5.1.9012)
    teal.widgets      0.4.2      2023-12-14 [1] CRAN (R 4.4.1)
    testthat        * 3.2.1.1    2024-04-14 [1] CRAN (R 4.4.1)
    tibble            3.2.1      2023-03-20 [1] CRAN (R 4.4.1)
    tidyr             1.3.1      2024-01-24 [1] CRAN (R 4.4.1)
    tidyselect        1.2.1      2024-03-11 [1] CRAN (R 4.4.1)
    urlchecker        1.0.1      2021-11-30 [1] CRAN (R 4.4.1)
    usethis         * 3.0.0      2024-07-29 [1] CRAN (R 4.4.1)
    utf8              1.2.4      2023-10-22 [1] CRAN (R 4.4.1)
    vctrs             0.6.5      2023-12-01 [1] CRAN (R 4.4.1)
    viridisLite       0.4.2      2023-05-02 [1] CRAN (R 4.4.1)
    waldo             0.6.0      2024-11-04 [1] CRAN (R 4.4.1)
    withr             3.0.2      2024-10-28 [1] CRAN (R 4.4.1)
    xtable            1.8-4      2019-04-21 [1] CRAN (R 4.4.1)

 [1] C:/Users/sanchosl/AppData/Local/R/win-library/4.4
 [2] C:/Program Files/R/R-4.4.1/library

 V ── Loaded and on-disk version mismatch.
 P ── Loaded and on-disk path mismatch.

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
@llrs-roche llrs-roche added the bug Something isn't working label Nov 8, 2024
@llrs-roche llrs-roche changed the title [Bug]: <title> [Bug]: Failing test UTF characters are replaced differently Nov 8, 2024
@llrs-roche llrs-roche added the core label Nov 8, 2024
@m7pr
Copy link
Contributor

m7pr commented Nov 8, 2024

I think that only breaks on Windows
https://github.com/insightsengineering/teal.slice/actions/runs/11648244059/job/32434448692#step:8:187

And you can see that it has been failing for the last 2 weeks
https://github.com/insightsengineering/teal.slice/actions/workflows/scheduled.yaml

image

llrs-roche added a commit that referenced this issue Nov 14, 2024
# Pull Request

Fixes #623 

After 1 year with an error and with `verify()` in place, it makes sense
to remove them.
I didn't keep any documentation or redirect users to other
functions/examples, (but it is hard for me to guess if users might not
know how to update their code).

The checks will fail due to #629

---------

Signed-off-by: Lluís Revilla <[email protected]>
Co-authored-by: Marcin <[email protected]>
@pawelru
Copy link
Contributor

pawelru commented Dec 3, 2024

@averissimo
Copy link
Contributor

It seems that R windows handles unicode characters differently.

We should move the HTML element's id generation to an incremental one instead of named-based one.

@averissimo
Copy link
Contributor

useBytes = TRUE could be a workaround before removing the named-based approach. It has the same result in Windows and Linux

Confirmed with the help of @llrs-roche who also shared the post in R-Project blog about this.

# Windows 🪟
id <- "\U41\U05E\U30\U5F\U7A\U1F4AA"
teal.slice:::sanitize_id(id)
#> [1] "h1724_A_0_z__"
pattern_escape <- "[^0-9A-Za-z_]"
id_new <- gsub(pattern_escape, "_", id)

id_new
#> [1] "A_0_z__"
# linux 🐧
id <- "\U41\U05E\U30\U5F\U7A\U1F4AA"

teal.slice:::sanitize_id(id)
#> [1] "h1724_A_0_z_"
pattern_escape <- "[^0-9A-Za-z_]"
id_new <- gsub(pattern_escape, "_", id, perl = TRUE)

id_new
#> [1] "A_0_z_"

@llrs-roche
Copy link
Contributor Author

This should be fixed by #632, closing.

Confirmed that with:

# Windows 🪟
id <- "\U41\U05E\U30\U5F\U7A\U1F4AA"
teal.slice:::sanitize_id(id)
#> [1] "h1724_A_0_z__"
pattern_escape <- "[^0-9A-Za-z_]"
id_new <- gsub(pattern_escape, "_", id, perl = TRUE) # Change compared above

id_new
#> [1] "A_0_z_"

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

No branches or pull requests

4 participants