summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2015-03-07 10:55:13 +0000
committerGabriel Scherer <gabriel.scherer@gmail.com>2015-03-07 10:55:13 +0000
commitefa9d3bd9eab489503cf98ea379c5f4e8950f5da (patch)
treee73c6e6c0d5d8bac93c2c5a0eb4e5fe652a9f982
parentbbd24c8bfd471561a74bd1ef4f44f34f81102076 (diff)
downloadocaml-efa9d3bd9eab489503cf98ea379c5f4e8950f5da.tar.gz
PR#6791: "%s@[", "%s@{" regression in Scanf
(Benoît Vaugon) git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15881 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Changes2
-rw-r--r--stdlib/scanf.ml6
-rw-r--r--testsuite/tests/lib-scanf/tscanf.ml7
3 files changed, 14 insertions, 1 deletions
diff --git a/Changes b/Changes
index 16bdd3572b..83f8c4e3af 100644
--- a/Changes
+++ b/Changes
@@ -159,6 +159,8 @@ Bug fixes:
- PR#6775: Digest.file leaks file descriptor on error
(Valentin Gatien-Baron)
- PR#6787: Soundness bug with polymorphic variants
+- PR#6791: "%s@[", "%s@{" regression in Scanf
+ (Benoît Vaugon)
- GPR#143: fix getsockopt behaviour for boolean socket options
(Anil Madhavapeddy and Andrew Ray)
- ocamlbuild on cygwin cannot find ocamlfind
diff --git a/stdlib/scanf.ml b/stdlib/scanf.ml
index 1372c41ae8..0144d38bdb 100644
--- a/stdlib/scanf.ml
+++ b/stdlib/scanf.ml
@@ -1125,6 +1125,12 @@ fun ib fmt readers -> match fmt with
let scan width _ ib = scan_string (Some stp) width ib in
let str_rest = String_literal (str, rest) in
pad_prec_scanf ib str_rest readers pad No_precision scan token_string
+ | String (pad, Formatting_gen (Open_tag (Format (fmt', _)), rest)) ->
+ let scan width _ ib = scan_string (Some '{') width ib in
+ pad_prec_scanf ib (concat_fmt fmt' rest) readers pad No_precision scan token_string
+ | String (pad, Formatting_gen (Open_box (Format (fmt', _)), rest)) ->
+ let scan width _ ib = scan_string (Some '[') width ib in
+ pad_prec_scanf ib (concat_fmt fmt' rest) readers pad No_precision scan token_string
| String (pad, rest) ->
let scan width _ ib = scan_string None width ib in
pad_prec_scanf ib rest readers pad No_precision scan token_string
diff --git a/testsuite/tests/lib-scanf/tscanf.ml b/testsuite/tests/lib-scanf/tscanf.ml
index 9dddd50da8..a93637ec04 100644
--- a/testsuite/tests/lib-scanf/tscanf.ml
+++ b/testsuite/tests/lib-scanf/tscanf.ml
@@ -1268,7 +1268,12 @@ sscanf "Hello \n" "%s%s%_1[ ]\n" (fun s1 s2 ->
sscanf "Hello\nWorld!" "%s\n%s%!" (fun s1 s2 ->
s1 = "Hello" && s2 = "World!") &&
sscanf "Hello\nWorld!" "%s\n%s@!%!" (fun s1 s2 ->
- s1 = "Hello" && s2 = "World")
+ s1 = "Hello" && s2 = "World") &&
+ (* PR#6791 *)
+ sscanf "Hello{foo}" "%s@{%s" (fun s1 s2 ->
+ s1 = "Hello" && s2 = "foo}") &&
+ sscanf "Hello[foo]" "%s@[%s" (fun s1 s2 ->
+ s1 = "Hello" && s2 = "foo]")
;;
test (test52 ())