JBehave
  1. JBehave
  2. JBEHAVE-709

Named parameters sorrounded by quotes are not handled properly

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.5.4
    • Fix Version/s: 3.6
    • Component/s: Core
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Wnen using jbehave with named parameters, order is not respected in parameter injection if the named parameters are sorrounded with non-white characters (for example, quotes).
      Here is a simple test:

      public class QuoteNamedParametersStory extends JUnitStory {
      
        public static class QuotNamedParametersSteps {
      
          @Then("\"$foo\" then \"$bar\"")
          public void otherOrderQuotes(@Named("bar") String bar, @Named("foo") String foo) {
            assertThat(foo, equalTo("foo"));
            assertThat(bar, equalTo("bar"));
          }
        }
      
        @Override
        public Configuration configuration() {
          return new MostUsefulConfiguration().useStoryReporterBuilder(new StoryReporterBuilder().withFormats(Format.CONSOLE).withFailureTrace(true));
        }
      
        @Override
        public List<CandidateSteps> candidateSteps() {
          return new InstanceStepsFactory(configuration(), new QuotNamedParametersSteps()).createCandidateSteps();
        }
      }
      

      And the corresponding quote_named_parameters_story.story:

      Scenario: quotes on named parameters are problematic...
      
      Then "foo" then "bar"
      

      I was able to fix it (and pass the above test successfully) by changing org.jbehave.core.parsers.RegexPrefixCapturingPatternParser.Parameter to:

      private class Parameter {
        private final int start;
        private final int end;
        private final String whitespaceIfAny;
        private final String name;
      
        public Parameter(String pattern, int start, int end,
            String whitespaceIfAny) {
          this.start = start;
          this.end = end;
          this.whitespaceIfAny = whitespaceIfAny;
          this.name = pattern.substring(start + prefix.length(), end - whitespaceIfAny.length()).trim();
        }
      
      }
      

        Activity

        Hide
        Rui Figueira added a comment -
        Show
        Rui Figueira added a comment - A patch for this issue is available at https://github.com/ruifigueira/jbehave-core/commit/2b69281edf2aae7d34e4b262c49ca88625b2b999
        Hide
        Mauro Talevi added a comment -

        Pulled with thanks.

        Show
        Mauro Talevi added a comment - Pulled with thanks.
        Mauro Talevi made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 3.6 [ 17721 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Rui Figueira
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: