Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
manuel-sanchez-vilt opened this issue Oct 30, 2023 · 1 comment

Comments

@manuel-sanchez-vilt
Copy link

manuel-sanchez-vilt commented Oct 30, 2023

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

@paulochang
Copy link
Contributor

I believe this would be a problem with the specific HTL implementation (Sling HTL engine, I suppose? The apropriate place to fill an issue would be https://github.com/apache/sling-org-apache-sling-scripting-sightly I think )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants