yoavnir / specs2016

New version of the specs pipeline stage based on what's in current CMS pipelines
MIT License
1 stars 1 forks source link

Incorrect result when using custom field or word separator in substring and getting the big part from the same expression #239

Closed yoavnir closed 3 months ago

yoavnir commented 5 months ago

Suppose my specification contains the following spec unit:

    SubString  WordSeparator /  Word 2 OF Word 3

Now let's suppose the input string is this:

The Epoch: 1/1/1970 at midnight

What I would expect is for the global word separator (by default, a space) to apply for calculating the big part. So the Big part would be the third word (as separated by spaces), so 1/1/1970.

Then to calculate the Spec Unit result, we switch the word separator to a slash (/) and the second word is 1, which should be the result.

Instead, the internal word separator applies to the entire unit. So taking the whole string and interpreting it as words separated by slashes, the words are:

  1. The Epoch: 1
  2. 1
  3. 1970 at midnight

So we take the third of those and try to find the second slash-separated word, and get an empty string.

yoavnir commented 3 months ago

The problem seems to be in DataField::getSubstringPart. Should check it more thoroughly. It looks like you can specify either ws or fs but not both?

yoavnir commented 3 months ago

It's less of an issue than I initially thought, because a substring is always going to have a range, and that range is either a word-range, or a field-range, or just a character range. So there's never really a point in specifying both a field separator and a word separator. Still, I made it so that this is allowed.

As for the original issue, yes, unless the user specified separators for the big part, specs used the separators of the small part. That was incorrect - it should have been the default separators and this is how it is now.