sxml or guile bug?

Christopher Lam <[email protected]>
Newsgroups gmane.lisp.guile.user,gmane.lisp.guile.bugs
Message-ID <CAKVAZZKHyTNeiapQCTysNCmricwvOZZm0ZWf0L7NT+FtuaCPBQ@mail.gmail.com>
Hi, we've identified an unusual behaviour in writing a test in gnucash. Can
anyone reproduce and confirmit?

I paste a simple .scm file, and its input test-file.html. Now, in
sxml-bug.scm, modify the <tr> index - from -1 to -2 i.e. access the
last/penultimate row etc.

Odd negative indices work, even negative indices lead to error. Odd (haha)
bug. See report for (tr -2) for example, pasted below.

==== sxml-bug.scm =====
(use-modules (sxml simple))
(use-modules (sxml xpath))
(use-modules (ice-9 textual-ports))
(define html (call-with-input-file "/tmp/test-file.html" get-string-all))
(define sx (xml->sxml html))

;; note this path: try different indices for the tr tag:
;; odd numbers -1 -3 -5 are ok
;; even numbers -2 -4 -6 will fail
(define path '(// (table 1) // (tr -1)))

(format #t "html=[~s]\n" html)
(format #t "sxpath is [~s]\n" path)
(format #t "result is [~s]\n" ((sxpath path) sx))
====

And the backtrace with -2

=====
Backtrace:
In ice-9/boot-9.scm:
  1752:10 18 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
          17 (apply-smob/0 #<thunk 7f7fd530d2e0>)
In ice-9/boot-9.scm:
    724:2 16 (call-with-prompt _ _ #<procedure default-prompt-handle…>)
In ice-9/eval.scm:
    619:8 15 (_ #(#(#<directory (guile-user) 7f7fd5312c80>)))
In ice-9/boot-9.scm:
   2836:4 14 (save-module-excursion _)
  4388:12 13 (_)
In /home/user/sources/sxml-bug.scm:
    20:30 12 (_)
In sxml/xpath.scm:
   254:18 11 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   254:18 10 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   254:18  9 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   254:18  8 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   254:18  7 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   252:22  6 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   252:22  5 (map-union #<procedure 7f7fd18f2ea0 at sxml/xpath.scm:…> …)
   254:18  4 (map-union #<procedure 7f7fd1901420 at sxml/xpath.scm:…> …)
   254:18  3 (map-union #<procedure 7f7fd1901420 at sxml/xpath.scm:…> …)
   252:22  2 (map-union #<procedure 7f7fd1901420 at sxml/xpath.scm:…> …)
   484:19  1 (loop _ ((tr -6)))
   181:24  0 (_ _)

sxml/xpath.scm:181:24: yikes!
=====
test-file.html (text/plain, 4.7 KB)
  read rows from the bottom

  From 01/01/23 to 12/31/23

   Sorting / Add indenting columns : Disabled
   Sorting / Secondary Key : none
   Sorting / Primary Subtotal : Disabled
   Sorting / Primary Subtotal for Date Key : none
   General / Add options summary : always
   General / Table for Exporting : Enabled
   Display / Totals : Disabled
   Display / Amount : single
   Display / Other Account Name : Disabled
   Display / Account Name : Enabled
   Display / Notes : Disabled
   Display / Memo : Disabled
   Display / Num : Disabled
   Accounts / Accounts : Bank

     Date   Description     Account        Amount
   01/03/23 $103 income Root.Asset.Bank [1]$103.00
   01/09/23 $109 income Root.Asset.Bank [2]$109.00
   01/15/23 $22 expense Root.Asset.Bank [3]-$22.00
   02/03/23 $103 income Root.Asset.Bank [4]$103.00
   02/09/23 $109 income Root.Asset.Bank [5]$109.00
   02/15/23 $22 expense Root.Asset.Bank [6]-$22.00
   03/03/23 $103 income Root.Asset.Bank [7]$103.00
   03/09/23 $109 income Root.Asset.Bank [8]$109.00
   03/15/23 $22 expense Root.Asset.Bank [9]-$22.00
   04/03/23 $103 income Root.Asset.Bank [10]$103.00
   04/09/23 $109 income Root.Asset.Bank [11]$109.00
   04/15/23 $22 expense Root.Asset.Bank [12]-$22.00
   05/03/23 $103 income Root.Asset.Bank [13]$103.00
   05/09/23 $109 income Root.Asset.Bank [14]$109.00
   05/15/23 $22 expense Root.Asset.Bank [15]-$22.00
   06/03/23 $103 income Root.Asset.Bank [16]$103.00
   06/09/23 $109 income Root.Asset.Bank [17]$109.00
   06/15/23 $22 expense Root.Asset.Bank [18]-$22.00
   07/03/23 $103 income Root.Asset.Bank [19]$103.00
   07/09/23 $109 income Root.Asset.Bank [20]$109.00
   07/15/23 $22 expense Root.Asset.Bank [21]-$22.00
   08/03/23 $103 income Root.Asset.Bank [22]$103.00
   08/09/23 $109 income Root.Asset.Bank [23]$109.00
   08/15/23 $22 expense Root.Asset.Bank [24]-$22.00
   09/03/23 $103 income Root.Asset.Bank [25]$103.00
   09/09/23 $109 income Root.Asset.Bank [26]$109.00
   09/15/23 $22 expense Root.Asset.Bank [27]-$22.00
   10/03/23 $103 income Root.Asset.Bank [28]$103.00
   10/09/23 $109 income Root.Asset.Bank [29]$109.00
   10/15/23 $22 expense Root.Asset.Bank [30]-$22.00
   11/03/23 $103 income Root.Asset.Bank [31]$103.00
   11/09/23 $109 income Root.Asset.Bank [32]$109.00
   11/15/23 $22 expense Root.Asset.Bank [33]-$22.00
   12/03/23 $103 income Root.Asset.Bank [34]$103.00
   12/09/23 $109 income Root.Asset.Bank [35]$109.00
   12/15/23 $22 expense Root.Asset.Bank [36]-$22.00

References

   1. gnc-register:split-guid=859032c8639e49b49501e9a0a1497ac5
   2. gnc-register:split-guid=cbe4ba7904514285a22913f3d41fde9d
   3. gnc-register:split-guid=fd07c28587454d1896ac3d90b491abc7
   4. gnc-register:split-guid=8d2376b51564402b8269654336eeee04
   5. gnc-register:split-guid=ea146a234ff742649b93b9a33fefae2e
   6. gnc-register:split-guid=8ab91494621f4bf1b0cdfc5601359459
   7. gnc-register:split-guid=0b489080220c436aae8614023054953d
   8. gnc-register:split-guid=7a94654477ec47a2a63093d34236ea1f
   9. gnc-register:split-guid=66c9c5bbdf514ba7b20f06eda93e0eeb
  10. gnc-register:split-guid=c83755eb16374818807ce38e796be8d4
  11. gnc-register:split-guid=eb2ce4371dae4116abf8e69f8b3af6f6
  12. gnc-register:split-guid=df341fa54f054d128abdee4340448305
  13. gnc-register:split-guid=597e3adb64eb4b41bf275170e055bd43
  14. gnc-register:split-guid=fe179202452a44dfb9a2540615323d38
  15. gnc-register:split-guid=ca46492548a14b448dbb4f67d4d571f5
  16. gnc-register:split-guid=0c8fb144e4154335a1c6dbc98f5ab53d
  17. gnc-register:split-guid=889517c233dc4c2f917a9e7c945028a4
  18. gnc-register:split-guid=7297930cce5c42ccbbe864e177db78e7
  19. gnc-register:split-guid=ba0f8fd1ce75411785d831f70d8a51b6
  20. gnc-register:split-guid=88fc84a2790448c3a273b7ea11da3bf0
  21. gnc-register:split-guid=a3d79534553f462ea3c6cd8d533b99bb
  22. gnc-register:split-guid=576cb90366c44bb1b942ea22a615bf1f
  23. gnc-register:split-guid=773905c9652c4ddc80ca4ff462375cd0
  24. gnc-register:split-guid=6c2135444dfc447b9c8c8872ae3dff36
  25. gnc-register:split-guid=64b5a4f8b67d40dfb617d322baa331a7
  26. gnc-register:split-guid=ae3c7904b80e44ee89a9c1e67b162b50
  27. gnc-register:split-guid=67293b53307843ceb4ed10a77119243c
  28. gnc-register:split-guid=285dd536ed844570aa1c313777d06821
  29. gnc-register:split-guid=f6c3a452d6264df3974d3a7042c6cba9
  30. gnc-register:split-guid=4a27b2af68fe4a3197173230a6915fbc
  31. gnc-register:split-guid=d96ca6c7ec5c476293da8cc1778648e8
  32. gnc-register:split-guid=2f762a28938443669db6c9e397fb8ec0
  33. gnc-register:split-guid=1db360a62cfe44e6a52e10864edff969
  34. gnc-register:split-guid=051b3f418f984dac82d6fa93469e6525
  35. gnc-register:split-guid=51e95c4897c74b87a058f55d5b6cc9ca
  36. gnc-register:split-guid=dbab36af60ce4edaaa56c536834edc39
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.