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

Scanf.unescaped fails on "\"" #6958

Closed
vicuna opened this issue Aug 14, 2015 · 4 comments
Closed

Scanf.unescaped fails on "\"" #6958

vicuna opened this issue Aug 14, 2015 · 4 comments

Comments

@vicuna
Copy link

vicuna commented Aug 14, 2015

Original bug ID: 6958
Reporter: AltGr
Status: closed (set by @xavierleroy on 2017-09-24T15:31:46Z)
Resolution: fixed
Priority: normal
Severity: minor
Fixed in version: 4.03.0+dev / +beta1
Category: standard library
Tags: junior_job
Monitored by: @hcarty

Bug description

I get:

Scanf.Scan_failure "scanf: bad input at char number 2: "end of input not found""

Steps to reproduce

run Scanf.unescaped """

@vicuna
Copy link
Author

vicuna commented Aug 15, 2015

Comment author: bvaugon

In fact, String.unescaped reverts an escaped string that follows the
OCaml lexing convention (as said by the documentation). It is
typically used to revert a call to String.escaped.

Here, the string """ (that contains only one char, a '"'), is an
invalid OCaml escaped string (and is, in particular, never returned by
String.escaped). It is refused by Scanf.unescaped as, for example, the
string "\x0g", since it does not follow the OCaml lexing convention.

May be you mean unescaping the string "\"" to obtain """.

However, the error message is not very clear, a small fix for that message may be useful...

@vicuna
Copy link
Author

vicuna commented Aug 17, 2015

Comment author: AltGr

Indeed. The thing is that Scanf.unescaped is more or less advertised as a general unescaping function, so it's tempting to use it just for interpreting \n, \t, \r, \000 and \x00 escapes, etc. ; in this regard, the limitation that it chokes on some (but not all) already unescaped characters is a bit surprising. Besides, there doesn't seem to be a good reason behind this limitation.

@vicuna
Copy link
Author

vicuna commented Aug 19, 2015

Comment author: @damiendoligez

At the very least, we should document the exception that is raised when the string does not follow the lexical conventions of OCaml.

@vicuna
Copy link
Author

vicuna commented Feb 3, 2016

Comment author: @damiendoligez

The documentation was fixed in commit aaba08b.

Since Scanf.unescaped is a parsing function, I don't find it surprising that it fails on bad inputs. If you wanted to make it total, you'd have to specify how to recover from syntax errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant