Commit b6b4d3b299490966524ee5a1a8ecc03c267af0c8
1 parent
1787d850
Add new method JSONParser::numberError
Showing
1 changed file
with
35 additions
and
5 deletions
libqpdf/JSON.cc
| ... | ... | @@ -620,6 +620,7 @@ namespace |
| 620 | 620 | private: |
| 621 | 621 | void getToken(); |
| 622 | 622 | void handleToken(); |
| 623 | + void numberError(); | |
| 623 | 624 | static std::string |
| 624 | 625 | decode_string(std::string const& json, qpdf_offset_t offset); |
| 625 | 626 | static void handle_u_code( |
| ... | ... | @@ -797,6 +798,39 @@ JSONParser::decode_string(std::string const& str, qpdf_offset_t offset) |
| 797 | 798 | } |
| 798 | 799 | |
| 799 | 800 | void |
| 801 | +JSONParser::numberError() | |
| 802 | +{ | |
| 803 | + if (*p == '.') { | |
| 804 | + if (number_saw_e) { | |
| 805 | + // QTC::TC("libtests", "JSON parse point after e"); | |
| 806 | + throw std::runtime_error( | |
| 807 | + "JSON: offset " + std::to_string(offset) + | |
| 808 | + ": numeric literal: decimal point after e"); | |
| 809 | + } else { | |
| 810 | + // QTC::TC("libtests", "JSON parse duplicate point"); | |
| 811 | + throw std::runtime_error( | |
| 812 | + "JSON: offset " + std::to_string(offset) + | |
| 813 | + ": numeric literal: decimal point already seen"); | |
| 814 | + } | |
| 815 | + } else if (*p == 'e') { | |
| 816 | + // QTC::TC("libtests", "JSON parse duplicate e"); | |
| 817 | + throw std::runtime_error( | |
| 818 | + "JSON: offset " + std::to_string(offset) + | |
| 819 | + ": numeric literal: e already seen"); | |
| 820 | + } else if ((*p == '+') || (*p == '-')) { | |
| 821 | + // QTC::TC("libtests", "JSON parse unexpected sign"); | |
| 822 | + throw std::runtime_error( | |
| 823 | + "JSON: offset " + std::to_string(offset) + | |
| 824 | + ": numeric literal: unexpected sign"); | |
| 825 | + } else { | |
| 826 | + QTC::TC("libtests", "JSON parse numeric bad character"); | |
| 827 | + throw std::runtime_error( | |
| 828 | + "JSON: offset " + std::to_string(offset) + | |
| 829 | + ": numeric literal: unexpected character " + std::string(p, 1)); | |
| 830 | + } | |
| 831 | +} | |
| 832 | + | |
| 833 | +void | |
| 800 | 834 | JSONParser::getToken() |
| 801 | 835 | { |
| 802 | 836 | enum { append, ignore, reread } action = append; |
| ... | ... | @@ -905,11 +939,7 @@ JSONParser::getToken() |
| 905 | 939 | action = reread; |
| 906 | 940 | ready = true; |
| 907 | 941 | } else { |
| 908 | - QTC::TC("libtests", "JSON parse numeric bad character"); | |
| 909 | - throw std::runtime_error( | |
| 910 | - "JSON: offset " + std::to_string(offset) + | |
| 911 | - ": numeric literal: unexpected character " + | |
| 912 | - std::string(p, 1)); | |
| 942 | + numberError(); | |
| 913 | 943 | } |
| 914 | 944 | break; |
| 915 | 945 | ... | ... |