From 4940ddb8f574662491dec257a964895621c3076e Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 22 Jul 2011 17:28:42 +0200 Subject: [PATCH] Fixed issue with matcher --- library/protocol/uri_template/src/uri_template.e | 10 +++++++--- .../tests/draft_50/test_uri_template_draft_05.e | 6 ++++++ .../protocol/uri_template/tests/test_uri_template.e | 7 +++++++ library/protocol/uri_template/uri_template-safe.ecf | 2 -- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/library/protocol/uri_template/src/uri_template.e b/library/protocol/uri_template/src/uri_template.e index d75af2e6..31bc58fa 100644 --- a/library/protocol/uri_template/src/uri_template.e +++ b/library/protocol/uri_template/src/uri_template.e @@ -178,7 +178,7 @@ feature -- Match else from l_expressions.start - p := 1 + p := 0 l_offset := 0 until l_expressions.after or not b @@ -187,10 +187,14 @@ feature -- Match vn := exp.expression q := exp.position --| Check text between vars - --| FIXME jfiat [2011/07/22] : check this ... + if p = q then --| There should be at least one literal between two expression --| {var}{foobar} is ambigous for matching ... - if q > p then + b := False + elseif q > p then + if p = 0 then + p := 1 + end t := tpl.substring (p, q - 1) s := a_uri.substring (p + l_offset, q + l_offset - 1) b := s.same_string (t) diff --git a/library/protocol/uri_template/tests/draft_50/test_uri_template_draft_05.e b/library/protocol/uri_template/tests/draft_50/test_uri_template_draft_05.e index 9d89ea5c..e6cac60c 100644 --- a/library/protocol/uri_template/tests/draft_50/test_uri_template_draft_05.e +++ b/library/protocol/uri_template/tests/draft_50/test_uri_template_draft_05.e @@ -29,6 +29,12 @@ feature -- Test routines local tpl: URI_TEMPLATE do + create tpl.make ("{version}/{id}") + uri_template_match (tpl, "v2/123", <<["version", "v2"], ["id" , "123"]>>, <<>>) + + create tpl.make ("api/{foo}{bar}/id/{id}") + uri_template_mismatch (tpl, "api/foobar/id/123") + create tpl.make ("api/foo/{foo_id}/{?id,extra}") uri_template_match (tpl, "api/foo/bar/", <<["foo_id", "bar"]>>, <<>>) uri_template_match (tpl, "api/foo/bar/?id=123", <<["foo_id", "bar"]>>, <<["id", "123"]>>) diff --git a/library/protocol/uri_template/tests/test_uri_template.e b/library/protocol/uri_template/tests/test_uri_template.e index 7297b30a..6f3eccbe 100644 --- a/library/protocol/uri_template/tests/test_uri_template.e +++ b/library/protocol/uri_template/tests/test_uri_template.e @@ -29,6 +29,13 @@ feature -- Test routines local tpl: URI_TEMPLATE do + create tpl.make ("{version}/{id}") + uri_template_match (tpl, "v2/123", <<["version", "v2"], ["id" , "123"]>>, <<>>) + + create tpl.make ("api/{foo}{bar}/id/{id}") + uri_template_mismatch (tpl, "api/foobar/id/123") + + create tpl.make ("api/foo/{foo_id}/{?id,extra}") uri_template_match (tpl, "api/foo/bar/", <<["foo_id", "bar"]>>, <<>>) uri_template_match (tpl, "api/foo/bar/?id=123", <<["foo_id", "bar"]>>, <<["id", "123"]>>) diff --git a/library/protocol/uri_template/uri_template-safe.ecf b/library/protocol/uri_template/uri_template-safe.ecf index dda82aa1..41c85f7b 100644 --- a/library/protocol/uri_template/uri_template-safe.ecf +++ b/library/protocol/uri_template/uri_template-safe.ecf @@ -40,8 +40,6 @@ - -