Skip to content

Data-sly-list specification does not accept its "end" option to be "0" even though it is a correct index #102

Description

@manuel-sanchez-vilt

Here is the specification: https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#226-list

"

  • Iterates over the content of each item in the attribute value, allowing to control the iteration through the following options:
    • begin - iteration begins at the item located at the specified index; first item of the collection has index 0
    • step - iteration will only process every step items of the collection, starting with the first one
    • end - iteration ends at the item located at the specified index (inclusive)
  • Element: shown only if the number of items from the attribute value is greater than 0, or if the attribute value is a string or number; when the begin value is used the element will be shown only if the begin value is smaller than the collection's size.

"

Expected Behaviour

I should be able to use data-sly-list for just one element even though it is the first item of a list.

Actual Behaviour

I can use data-sly-list for just one element as long as it is not the first element of a list because the "end" option cannot be "0". This is not stated in the specification but it can be seen in the compiled code:

boolean var_validstartstepend16 = (((org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperator.lt(var_begin13, var_size11)) && ((!(org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperator.lt(var_begin13, 0))) && true)) && (!(org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperator.leq(var_end15, 0))));

Reproduce Scenario (including but not limited to)

Steps to Reproduce

Just write the following code in any valid htl file.

<p>The following test is OK and it should print "2"</p>
<ul data-sly-list="${[1, 2, 3] @ begin = 1, end = 1}">
    <li>${item}</li>
</ul>
<p>The following test is not OK and it should print "1" but it does not print the list because the "end" option cannot be "0"</p>
<ul data-sly-list="${[1, 2, 3] @ begin = 0, end = 0}">
    <li>${item}</li>
</ul>

Example:

  1. Download the latest SDK and install the Core Components project
  2. Go to http://localhost:4502/crx/de/index.jsp#/apps/core/wcm/components/text/v2/text/text.html
  3. Add the above code
  4. Go to http://localhost:4502/editor.html/content/core-components-examples/library/core-content/text.html and you should be able to see the test results.

Platform and Version

Any (Cloud and 6.5 for example).

Sample Code that illustrates the problem

<p>The following test is OK and it should print "2"</p>
<ul data-sly-list="${[1, 2, 3] @ begin = 1, end = 1}">
    <li>${item}</li>
</ul>
<p>The following test is not OK and it should print "1" but it does not print the list because the "end" option cannot be "0"</p>
<ul data-sly-list="${[1, 2, 3] @ begin = 0, end = 0}">
    <li>${item}</li>
</ul>

Logs taken while reproducing problem

No logs needed

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions