When they say you can't break it

61 views
Skip to first unread message

Ben Brawn

unread,
Apr 21, 2022, 1:05:43 AM4/21/22
to Numbas Users
HI Christian, a colleague of mine was writing a question and somehow broke it. The browser can't even load the question's editor page entirely. 

He says that he was manually fixing variable values to check if his question worked as expected, when he got distracted and left what he was doing. 


F12 mentions the following by that's a red herring (although maybe something that needs to be looked at for other reasons?)
  1. Audit usage of navigator.userAgent, navigator.appVersion, and navigator.platform
    1. A page or script is accessing at least one of navigator.userAgent, navigator.appVersion, and navigator.platform. Starting in Chrome 101, the amount of information available in the User Agent string will be reduced.

      To fix this issue, replace the usage of navigator.userAgent, navigator.appVersion, and navigator.platform with feature detection, progressive enhancement, or migrate to navigator.userAgentData.

      Note that for performance reasons, only the first access to one of the properties is shown.

    2. AFFECTED RESOURCES
      1. 2 sources

        1. MathJax.js:1
          MathJax.js:1
      • Learn more: User-Agent String Reduction


Ben Brawn

unread,
Apr 21, 2022, 2:33:07 AM4/21/22
to Numbas Users
I've found the issue. Apparently, rationals don't like large powers, e.g. (1/100)^300 hangs the editor but 0.01^300 doesn't.

I found this by downloading the source file of the question by putting in the correct URL, and then deleting variables one by one and reuploading the source file until I found the offending variables. A certain calculation using dpformat to two decimal places kept coming up as NaN.00 when it really shouldn't have been that.

I've fixed his question but it is weird that we couldn't get into the original at all. 

Christian Lawson-Perfect

unread,
Apr 26, 2022, 8:20:50 AM4/26/22
to numbas...@googlegroups.com
It turns out the source of the problem is that the code to display a fraction tries to reduce it to lowest terms, and since the numerator and denominator are stored as standard JS numbers, (1/100)^300 ends up as 1/infinity. The greatest common divisor algorithm used to reduce the fraction got stuck in an infinite loop.
I've changed the gcd algorithm so it returns 1 if either argument is ±infinity, so fractions like this shouldn't crash the page any more.

When we drop IE 11 support, which I'd like to do this year, we could look at using the BigInt type to represent integers, which would allow arbitrarily large numbers.

--
You received this message because you are subscribed to the Google Groups "Numbas Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numbas-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/numbas-users/37afccdd-1be1-44b0-af75-39996a0dd03dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages