-
Notifications
You must be signed in to change notification settings - Fork 23
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
Parameter parsing problem #24
Comments
bq. snooze doesn't like parsing certain jwt parameters. What are jwt parameters? |
JSON Web Tokens, used for OIDC. For example... ...will cause the error I describe above. |
Having a look at this. By the way, your workaround is also known as |
I can't reproduce this. Can you just try (SNOOZE-SAFE-SIMPLE-READ::PARSE-INTEGER-THEN-FLOAT "7e338383-9712-42f8-ab5c-b9597e36847b.00af646c-8d59-428a-9c39-4a9e8975942d.3006bb38-909e-458e-a48d-6362bcf55e9e") In a REPL? |
Right. The problem is that the PARSE-FLOAT library has a bug, or at least different behaviour, in SBCL, it signals a a
Allegro ACL works, but returns "infinity". I'll come up with a fix soon, but you can use that one iof you wish in the meantime. |
Also delete the "original condition backtrace" since that was a big fat lie. * common.lisp (check-arglist-compatible): Pass correct lambda list to condition object. (explain-condition-failsafe): Simplify. (explain-failsafe condition): Shut up. (explain-failsafe error-when-explaining) (explain-failsafe unconvertible-argument) (explain-failsafe invalid-uri-structure) (explain-failsafe :before resignalled-condition) (explain-failsafe :After resignalled-condition): Simplify. * common.lisp (resignalled-condition): Remove original-condition-backtrace.
How comes that Snooze tries to convert this to a float? |
That's part of the normal reader logic. Among other things, conversion to a float is tried (after integer). Mind you, In general, when parsing (which is CL is called "reading") you can't easily know until you read enough that something in a string or a string isn't of a certain type. |
Sure, looking at the first 4, or even 8 digits you have a number. But a dash '-' is not part of a number, so this should never even be tried to convert to a float or int. In any case what would be the solution for this, to keep it as a string, and let the 'user' do the conversion, if any conversion must be done? |
Anyway, I guess the OP has something working. |
You're misunderstanding the problem. Try CL: READ on the same string and
tell me what you get. The solution is to do what I did, which makes does
the reader do what CL:READ does, except that it doesn't intern symbols,
which is the point.
…On Sat, Aug 1, 2020, 17:18 Manfred Bergmann ***@***.***> wrote:
the first 4 characters of the string at hand, is a valid float. But when
you crank up the exponent it becomes some infinity number
Sure, looking at the first 4, or even 8 digits you have a number. But a
dash '-' is not part of a number, so this should never even be tried to
convert to a float or int.
In any case what would be the solution for this, to keep it as a string,
and let the 'user' do the conversion?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#24 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC6PQ7IBIUMERFY2EKN4XLR6Q557ANCNFSM4PL7QY7Q>
.
|
Could be I misunderstand. A result of 'infinity' for this string as a float is a completely wrong result. |
Maybe this clears it up SNOOZE-SAFE-SIMPLE-READ> (cl:read-from-string "123")
123 (7 bits, #x7B, #o173, #b1111011)
3 (2 bits, #x3, #o3, #b11)
SNOOZE-SAFE-SIMPLE-READ> (safe-simple-read-from-string "123")
123 (7 bits, #x7B, #o173, #b1111011)
3 (2 bits, #x3, #o3, #b11)
SNOOZE-SAFE-SIMPLE-READ> (cl:read-from-string "123.3e2")
12330.0
7 (3 bits, #x7, #o7, #b111)
SNOOZE-SAFE-SIMPLE-READ> (safe-simple-read-from-string "123.3e2")
12330.0
7 (3 bits, #x7, #o7, #b111)
SNOOZE-SAFE-SIMPLE-READ> (cl:read-from-string "123.3e2foo")
123.3E2FOO
10 (4 bits, #xA, #o12, #b1010)
SNOOZE-SAFE-SIMPLE-READ> (type-of *)
SYMBOL
SNOOZE-SAFE-SIMPLE-READ> (safe-simple-read-from-string "123.3e2foo")
123.3E2FOO
10 (4 bits, #xA, #o12, #b1010)
SNOOZE-SAFE-SIMPLE-READ> (type-of *)
SYMBOL
SNOOZE-SAFE-SIMPLE-READ> (safe-simple-read-from-string "123.3e2fooasd")
; Debugger entered on #<SNOOZE-READER-ERROR SAFE-SIMPLE-READ-FROM-STRING refusing to intern a new symbol "123.3e2fooasd" in #<PACKAGE "SNOOZE-SAFE-SIMPLE-READ">>
SNOOZE-SAFE-SIMPLE-READ> (safe-simple-read-from-string "123.3e2fooasd" t)
#:123.3E2FOOASD
13 (4 bits, #xD, #o15, #b1101)
SNOOZE-SAFE-SIMPLE-READ> (type-of *)
SYMBOL
If you pass
Sure, but
Also, I have fixed the problem in a proper commit. |
I'm not sure what the purpose would be for
That may be true. I'm looking at that from an idealistic point of view. |
You may call it opinionated, but I would note it is not "my" opinion. It is that of the Common Lisp designers. They are the ones who designed Then you can generate perfect routes from the functions you create trivially with And yes, it's true, as I explain in the README, you can override at different levels of granularity it so that something you want designate an X becomes a X in your Lisp code as passed to your routes. By default, in Snooze, as in CL itself, things that don't designate numbers designate symbols. You can make a string designate a string, if you really need to. But most strings passed around in URIs designate other things, actual objects in your code. So before doing that, ask yourself it it's worth it and perhaps learn to embrace the symbol, which is the most understated and underrated feature in Common Lisp. And yes, that was my opinion. |
Read the Hyperspec for |
The Some frameworks in the Java world (where I mostly work) allow to annotate the desired type of query parameter. Then the framework will try to convert the parameter to the desired type. However, it should not do this without any information about what the user expects. Maybe a The |
Sure thing. Maybe a 'taking junk data into account' is useful for certain scenarios. |
Snooze is here to disprove you :-). If what you say were true, then Snooze would have been impossible to achieve, and yet, here it is. One thing I like in CL isn't bound by dogmatic theories in books, even the "Gang of four" sacred gospel, which was written for 90's Java and C++ and makes no sense in CL. I'm not the first person to suggest a Common Lisp HTTP URL router, by the way. It had been suggested before I started writing Snooze, but I didn't know about it. It used method combinations and looked really nice. I'll try to find the reference.
I can't know in Snooze what the "user" means to do. It's all a question of defaults and suggestions: Snooze by defaults suggests a way to see strings using symbols, which are basically strings onto which many useful properties have been attached. I completely fail to see how any generality is lost in this step. And as you yourself noted, if you'd rather override this suggestion and convert into monkeys or sausages inside your But if you want to go the Java route, by all means. Last time I checked, Java wasn't the best language for concise code. I may be wrong, I haven't used it seriously in 10 years. By the way, I see you're knowledgeable in design patterns, and in the Java world you must be indeed. Have you read this 25 year old paper? by Peter Norvig? It tells you, among other things, that the singleton design pattern is transparent or invisible in Common Lisp, if you use a constant. Which a symbol is. I wonder if you have an actual problem to show me or are just talking about hypothetical questions. If you have an actual REST designing problem, I'd be glad to look at it and maybe suggest how I would model it Lisp/Snooze. Then you can come up with a non-Snooze (and maybe non-Lisp) implementation and we can discuss the pros and cons of each alternative.
And don't know if that is what you are suggesting, but contrary to popular ignorance, Common Lisp is not case insensitive. If Snooze isn't answering to well to this, then Snooze can be fixed, surely, just open a new issue with an example where this makes a difference.
I'm not doing it "for HTTP". I'm doing it as a part of an implementation detail for a non-symbol-interning simplified reader. I'm quite sure you can get exactly the same results with a different implementation, that doesn't use anything but low-level binary manipulation functions or whatever. Submit your suggestion in a pull request: if it's faster, more maintainable, and doesn't break any tests, I will merge it. |
In fact I did.
I had, yes. I've worked around it.
|
It is called "Design Patterns", so I think that's a pretty bold statement (that you can make to its author, it's besides the point of this issue).
What is "the repository" in your example, Manfred? Is it a SQL database or something? Or is it a Lisp data structure, like an hash table, mapping blog "names" to BTW, this in unrelated, but if you need a default value for the
Your suggestion is of course possible to implement (though declaration forms usually go inside the function not outside them). But you can implement the macro |
Actually, this isn't a good idea, for reasons I can explain. Better make a
then use it like:
or
You'll probably need to MOP for this, so you can grab the parameter by the name from the generic function's lambda list. |
My curiosity led me to https://github.com/mdbergmann/cl-swbymabeweb, which is where you have this problem. You could store blog entries by sym names, instead of strings. But if you find this akward for some reason, even in its current state, the Also, and this is just an opinion, I think your system could be simplified to trigger errors as soon as possible so that you can follow the stack (instead of using a combination of That said, I like these dynamic systems which make blogs from the filesystem, I have designed a couple myself. |
I think there was a miscommunication. Peter Norvig's paper of course is about design patterns, or the GoF book "Design Patterns".
Indeed, that's where I use Snooze. I first used Caveman2, then step by step pretty much replaced any of it. That fact that I chose Snooze tells a story.
Yeah, I have to look this up. Indeed, the decoding of URL encodings in the URI path components should be done on a system boundary, maybe by Snooze, or at the latest in the route handler. In any case, in my simple application it works OK.
I will check this out, thanks. |
Ah OK ealier you said:
Which puzzled me, since the presentation (not actually a paper) is called "Design Patterns", explains what they are, including how languages like Lisp and Dylan make some patterns "transparent".
Agree, I will make an issue. I think the best way is to work like Lisp itself by default, i.e. work with |
I've made #25 to track the case-sensitivity problem |
OK, thanks. |
snooze doesn't like parsing certain jwt parameters. I worked around this thusly:
Here's the error:
The text was updated successfully, but these errors were encountered: