Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Issue #107
Browse files Browse the repository at this point in the history
Fixes #107. Amended regex PARAMETER_IDENTIFIER to allow % encoded characters and added tests for valid, invalid and incomplete % encoding.

Note: This was commit was orginally missed out from the shared/refactor-integration, pressumably by a mistake

Conflicts:
	src/ParameterDefinitonParser.h
  • Loading branch information
kuangmarkeleven authored and Z committed Sep 15, 2014
1 parent e0086ce commit 169e689
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ParameterParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define PARAMETER_VALUE "`([^`]+)`"

/** Parameter Identifier */
#define PARAMETER_IDENTIFIER "([[:alnum:]_.-]+)"
#define PARAMETER_IDENTIFIER "(([[:alnum:]_.-])*|(%[A-Fa-f0-9]{2})*)+"

/** Lead in and out for comma separated values regex */
#define CSV_LEADINOUT "[[:blank:]]*,?[[:blank:]]*"
Expand Down
89 changes: 88 additions & 1 deletion test/test-ParametersParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "snowcrashtest.h"
#include "ParametersParser.h"
#include "snowcrash.h"

using namespace snowcrash;
using namespace snowcrashtest;
Expand Down Expand Up @@ -187,7 +188,7 @@ TEST_CASE("Recognize parameter when there is no description on its signature and
REQUIRE(parameter.values[3] == "vent");
}

TEST_CASE("Parentheses in parameter example ", "[parameters][issue][#109][now]")
TEST_CASE("Parentheses in parameter example ", "[parameters][issue][#109]")
{
// Blueprint in question:
//R"(
Expand Down Expand Up @@ -215,3 +216,89 @@ TEST_CASE("Parentheses in parameter example ", "[parameters][issue][#109][now]")
REQUIRE(parameters[0].exampleValue == "substringof('homer', id)");
REQUIRE(parameters[0].description == "test");
}

TEST_CASE("Percentage encoded characters in parameter name ", "[parameters][percentageencoding][issue][#107]")
{
// Blueprint in question:
//R"(
//# GET /{id%5b%5d}
//+ Parameters
// + id%5b%5d (optional, oData, `substringof('homer', id)`) ... test
//
//+ response 204
//");
mdp::ByteBuffer source = \
"# GET /{id%5b%5d}\n"\
"+ Parameters\n"\
" + id%5b%5d (optional, oData, `substringof('homer', id)`) ... test\n"\
"\n"\
"+ response 204\n";

Blueprint blueprint;
Report report;

parse(source, 0, report, blueprint);

REQUIRE(report.error.code == Error::OK);
REQUIRE(report.warnings.empty());

REQUIRE(blueprint.resourceGroups.size() == 1);
REQUIRE(blueprint.resourceGroups[0].resources.size() == 1);
REQUIRE(blueprint.resourceGroups[0].resources[0].actions.size() == 1);
REQUIRE(blueprint.resourceGroups[0].resources[0].actions[0].description.empty());
REQUIRE(blueprint.resourceGroups[0].resources[0].actions[0].parameters.size() == 1);
REQUIRE(blueprint.resourceGroups[0].resources[0].actions[0].parameters[0].name == "id%5b%5d");
REQUIRE(blueprint.resourceGroups[0].resources[0].actions[0].parameters[0].type == "oData");
REQUIRE(blueprint.resourceGroups[0].resources[0].actions[0].parameters[0].exampleValue == "substringof('homer', id)");
REQUIRE(blueprint.resourceGroups[0].resources[0].actions[0].parameters[0].description == "test");
}

TEST_CASE("Invalid percentage encoded characters in parameter name ", "[invalid][parameters][percentageencoding][issue][#107]")
{
// Blueprint in question:
//R"(
//# GET /{id%5z}
//+ Parameters
// + id%5z (optional, oData, `substringof('homer', id)`) ... test
//
//+ response 204
//");
mdp::ByteBuffer source = \
"# GET /{id%5z}\n"\
"+ Parameters\n"\
" + id%5z (optional, oData, `substringof('homer', id)`) ... test\n"\
"\n"\
"+ response 204\n";

Blueprint blueprint;
Report report;

parse(source, 0, report, blueprint);
REQUIRE(report.error.code == Error::OK);
REQUIRE(report.warnings.size() == 3);
}

TEST_CASE("Incomplete percentage encoded characters in parameter name ", "[incomplete][parameters][percentageencoding][issue][#107]")
{
// Blueprint in question:
//R"(
//# GET /{id%}
//+ Parameters
// + id% (optional, oData, `substringof('homer', id)`) ... test
//
//+ response 204
//");
mdp::ByteBuffer source = \
"# GET /{id%}\n"\
"+ Parameters\n"\
" + id% (optional, oData, `substringof('homer', id)`) ... test\n"\
"\n"\
"+ response 204\n";

Blueprint blueprint;
Report report;

parse(source, 0, report, blueprint);
REQUIRE(report.error.code == Error::OK);
REQUIRE(report.warnings.size() == 3);
}

0 comments on commit 169e689

Please sign in to comment.