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

"a = 1" parsing gives invalid xml text (R 3.6.1) #5

Closed
russHyde opened this issue Aug 13, 2019 · 2 comments
Closed

"a = 1" parsing gives invalid xml text (R 3.6.1) #5

russHyde opened this issue Aug 13, 2019 · 2 comments

Comments

@russHyde
Copy link

russHyde commented Aug 13, 2019

Hi. There's an issue running some xmlparsedata-dependent code within the tests for lintr on R-3.6.1 (r-lib/lintr#384) and I think it relates to xmlparsedata.

If I clone the current master (99a30b1) for xmlparsedata and run in an R-3.6.1 environment:

# from xmlparsedata directory
devtools::load_all()
devtools::test() # no errors are thrown for the existing tests
xml2::read_xml(xml_parse_data(parse(text = "a = 1", keep.source = TRUE)))
Error in doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html = as_html,  : 
  Opening and ending tag mismatch: expr line 8 and equal_assign [76]
cat(xml_parse_data(parse(text = "a = 1", keep.source = TRUE), pretty = TRUE), file = "")

<?xml version="1.0" encoding="UTF-8"standalone="yes" ?>
<exprlist>
  <equal_assign line1="1" col1="1" line2="1" col2="5" start="7" end="11">
    <expr line1="1" col1="1" line2="1" col2="1" start="7" end="7">
      <SYMBOL line1="1" col1="1" line2="1" col2="1" start="7" end="7">a</SYMBOL>
    </expr>
    <EQ_ASSIGN line1="1" col1="3" line2="1" col2="3" start="9" end="9">=</EQ_ASSIGN>
    <expr line1="1" col1="5" line2="1" col2="5" start="11" end="11">
      <NUM_CONST line1="1" col1="5" line2="1" col2="5" start="11" end="11">1</NUM_CONST>
    </equal_assign>
  </expr>
</exprlist>

The xml that is produced isn't legal: equal_assign is interleaved with one of the exprs.

I with <- as the assignment operator, the xml is fine:

cat(xml_parse_data(parse(text = "a <- 1", keep.source = TRUE), pretty = TRUE), file = "")

<?xml version="1.0" encoding="UTF-8"standalone="yes" ?>
<exprlist>
  <expr line1="1" col1="1" line2="1" col2="6" start="8" end="13">
    <expr line1="1" col1="1" line2="1" col2="1" start="8" end="8">
      <SYMBOL line1="1" col1="1" line2="1" col2="1" start="8" end="8">a</SYMBOL>
    </expr>
    <LEFT_ASSIGN line1="1" col1="3" line2="1" col2="4" start="10" end="11">&lt;-</LEFT_ASSIGN>
    <expr line1="1" col1="6" line2="1" col2="6" start="13" end="13">
      <NUM_CONST line1="1" col1="6" line2="1" col2="6" start="13" end="13">1</NUM_CONST>
    </expr>
  </expr>
</exprlist>
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS

Matrix products: default
BLAS/LAPACK: /home/ah327h/tools/miniconda3/envs/pkgs_lintr_361/lib/libopenblasp-r0.3.6.so

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] xmlparsedata_1.0.2.9000 testthat_2.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2        rstudioapi_0.10   xml2_1.2.2        magrittr_1.5
 [5] usethis_1.5.1     devtools_2.1.0    pkgload_1.0.2     R6_2.4.0
 [9] rlang_0.4.0       tools_3.6.1       pkgbuild_1.0.4    sessioninfo_1.1.1
[13] cli_1.1.0         withr_2.1.2       remotes_2.1.0     assertthat_0.2.1
[17] digest_0.6.20     rprojroot_1.3-2   crayon_1.3.4      processx_3.4.1
[21] callr_3.3.1       fs_1.3.1          ps_1.3.0          praise_1.0.0
[25] memoise_1.1.0     glue_1.3.1        compiler_3.6.1    desc_1.2.0
[29] backports_1.1.4   prettyunits_1.0.2
@russHyde
Copy link
Author

However, if I run the same code in a R 3.5.1 environment:

devtools::load_all()
Loading xmlparsedata
> 
> devtools::test()
Loading xmlparsedata
Testing xmlparsedata
✔ |  OK F W S | Context
✔ |  17       | xmlparsedata [0.2 s]

══ Results ═════════════════════════════════════════════════════════════════════
Duration: 0.2 s

OK:       17
Failed:   0
Warnings: 0
Skipped:  0

Woot!
> 
# legal xml can be constructed:
> xml2::read_xml(xml_parse_data(parse(text = "a = 1", keep.source = TRUE)))
{xml_document}
<exprlist>
[1] <expr line1="1" col1="1" line2="1" col2="1" start="7" end="7">\n  <SYMBOL ...
[2] <EQ_ASSIGN line1="1" col1="3" line2="1" col2="3" start="9" end="9">=</EQ_ ...
[3] <expr line1="1" col1="5" line2="1" col2="5" start="11" end="11">\n  <NUM_ ...
# and the xml looks fine
> cat(xml_parse_data(parse(text = "a = 1", keep.source = TRUE), pretty = TRUE), file = "")

<?xml version="1.0" encoding="UTF-8"standalone="yes" ?>
<exprlist>
  <expr line1="1" col1="1" line2="1" col2="1" start="7" end="7">
    <SYMBOL line1="1" col1="1" line2="1" col2="1" start="7" end="7">a</SYMBOL>
  </expr>
  <EQ_ASSIGN line1="1" col1="3" line2="1" col2="3" start="9" end="9">=</EQ_ASSIGN>
  <expr line1="1" col1="5" line2="1" col2="5" start="11" end="11">
    <NUM_CONST line1="1" col1="5" line2="1" col2="5" start="11" end="11">1</NUM_CONST>
  </expr>
</exprlist>
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS

Matrix products: default
BLAS/LAPACK: /home/ah327h/tools/miniconda3/envs/pkgs_lintr/lib/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xmlparsedata_1.0.2.9000 testthat_2.1.1         

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1        rstudioapi_0.10   xml2_1.2.0        magrittr_1.5     
 [5] usethis_1.5.1     devtools_2.1.0    pkgload_1.0.2     R6_2.4.0         
 [9] rlang_0.4.0       tools_3.5.1       pkgbuild_1.0.3    sessioninfo_1.1.1
[13] cli_1.1.0         withr_2.1.2       remotes_2.1.0     assertthat_0.2.1 
[17] digest_0.6.20     rprojroot_1.3-2   crayon_1.3.4      processx_3.4.0   
[21] callr_3.3.0       fs_1.3.1          ps_1.3.0          praise_1.0.0     
[25] memoise_1.1.0     glue_1.3.1        compiler_3.5.1    desc_1.2.0       
[29] backports_1.1.4   prettyunits_1.0.2

@russHyde
Copy link
Author

Closed in #6

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

No branches or pull requests

1 participant