Skip to content

Conversation

@beardhatcode
Copy link

@beardhatcode beardhatcode commented Mar 28, 2025

Summary

preProcessedFileSubstitution did not work correctly if an empty map was given. In this case variables["ACCESS_TOKEN"] would be read as "" as that key was not present in the map.

Poco::replaceInPlace would in turn replace the %ACCESS_TOKEN% with "", while it should just keep the not specified parts as is.

I chose to add a function rather than ifs in the body to prevent future mistakes from happening.

Before this change I got an error when running the unittests from nix (see NixOS/nixpkgs#393618 (comment)
):

< orig (the one that is made with Poco::replaceInPlace)
> recon (the one that is made by .substitute(...))
10c10
< collabora-online>   <input type="hidden" id="init-buy-product-url" value="" />
---
> collabora-online>   <input type="hidden" id="init-buy-product-url" value="%BUYPRODUCT_URL%" />
12c12
< collabora-online>   <input type="hidden" id="init-css-vars" value="" />
---
> collabora-online>   <input type="hidden" id="init-css-vars" value="<!--%CSS_VARIABLES%-->" />
16c16
< collabora-online> <input type="hidden" id="init-branding-name" value="" />
---
> collabora-online> <input type="hidden" id="init-branding-name" value="%BRANDING_THEME%" />
145,148c145,148
< collabora-online>       data-access-token = ""
< collabora-online>       data-access-token-ttl = ""
< collabora-online>       data-access-header = ""
< collabora-online>       data-post-message-origin-ext = ""
---
> collabora-online>       data-access-token = "%ACCESS_TOKEN%"
> collabora-online>       data-access-token-ttl = "%ACCESS_TOKEN_TTL%"
> collabora-online>       data-access-header = "%ACCESS_HEADER%"
> collabora-online>       data-post-message-origin-ext = "%POSTMESSAGE_ORIGIN%"
167,168c167,168
< collabora-online>       data-ui-defaults = ""
< collabora-online>       data-check-file-info-override = ""
---
> collabora-online>       data-ui-defaults = "%UI_DEFAULTS%"
> collabora-online>       data-check-file-info-override = "%CHECK_FILE_INFO_OVERRIDE%"
181c181
< collabora-online>  <!-- logo onclick handler -->
---
> collabora-online> <!--%BRANDING_JS%--> <!-- logo onclick handler -->
182a183,184
> collabora-online> - orig != recon
> collabora-online> Failures !!!

Checklist

  • I have run make prettier-write and formatted the code.
  • All commits have Change-Id
  • I have run tests with make check -> ran through nix
  • I have issued make run and manually verified that everything looks okay -> even ran it through nextcloud
  • Documentation (manuals or wiki) has been updated or is not required

@welcome
Copy link

welcome bot commented Mar 28, 2025

Thanks for opening this pull request!

Things that will help get your PR across the finish line:

@beardhatcode beardhatcode force-pushed the master branch 2 times, most recently from d1fc372 to 220bf2a Compare March 28, 2025 16:56
@beardhatcode
Copy link
Author

Hmmm, it seems that the CI here does exactly the opposite...

@github-project-automation github-project-automation bot moved this from To Review to Done in Collabora Online Mar 28, 2025
@beardhatcode

This comment was marked as outdated.

@beardhatcode beardhatcode reopened this Mar 28, 2025
@github-project-automation github-project-automation bot moved this from Done to In Progress in Collabora Online Mar 28, 2025
@meven meven requested a review from Ashod March 31, 2025 09:31
@meven
Copy link
Contributor

meven commented Mar 31, 2025

Seems very sensible to me.

Placeholder key have no value in template output.

@beardhatcode
Copy link
Author

beardhatcode commented Mar 31, 2025

Updated the top post

I figured it out, what the test did was

for(file in files){
   orig = file.subsitute(variables)
   recon = Poco::replaceInPlace(....,vaiables["SOME_KEY"])
   test_same(orig,recon)
}

if you unroll this loop you would get:

    // iter 0 all fine
   orig = file1.subsitute(vars);
   recon = Poco::replaceInPlace(read(file1),vars["SOME_KEY"]); // <- this sets vars["SOME_KEY"]=""
   test_same(orig,recon);

    // iter 1 -> problem,s
   orig = file2.subsitute(vars); // <- this vars is different, as it is no longer empty but {"SOME_KEY"→""}
   recon = Poco::replaceInPlace(read(file2),vars["SOME_KEY"]);
   test_same(orig,recon);

Because the order of the iterations (files reported by the file system) on my machine was different than those in CI

  • CI the first file that was used was wasm.html (which does not contain and %VAR%), so in all future iterations the modified vars setting everything to the empty string was used incuding for cool.html
  • on my machine the first file was cool.html (which does contain %VAR%), so there it did the substitution correctly (leaving all the %VAR%) since vars was empty, but that did not correspond to the Poco::replaceInPlace

My files may have been in a different order because I was using nix and/or because my poco version was different.

beardhatcode added a commit to beardhatcode/nixpkgs that referenced this pull request Mar 31, 2025
@beardhatcode
Copy link
Author

beardhatcode commented Mar 31, 2025

force-pushed a typo fix and adding const to the variables arguments

@meven meven enabled auto-merge (rebase) April 4, 2025 10:23
auto-merge was automatically disabled May 7, 2025 07:02

Head branch was pushed to by a user without write access

@beardhatcode beardhatcode force-pushed the master branch 2 times, most recently from cf3366f to 94adc8a Compare May 7, 2025 07:03
@beardhatcode
Copy link
Author

Rebased

@beardhatcode
Copy link
Author

@Ashod , just quickly checking my PRs. If there's anything else I can
provide or if you'd like to discuss further in order to get this merged, please let me know!

@beardhatcode
Copy link
Author

Rebased

@britter
Copy link

britter commented Oct 26, 2025

Any change to get this merged?

preProcessedFileSubstitution did not work correctly if an empty map was
given. In this case `variables["ACCESS_TOKEN"]` would be read as `""` as
that key was not present in the map, addtionally, it would be added.

Poco::replaceInPlace would in turn replace the `%ACCESS_TOKEN%` with `""`,
while it should just keep the not specified parts as is. On top op that,
now variables is modified so in the next iteration of the loop the test
is no longer the same.

I chose to add a function rather than ifs in the body to prevent future
mistakes from happening. This does however make the code more complex

I also made variables a const argument

Change-Id: 8d84961da571686c39effa6d5b43918151da1be4
Signed-off-by: Robbert Gurdeep Singh <[email protected]>
@beardhatcode
Copy link
Author

Hi @Ashod and maintainers — I've rebased the branch onto master to keep it up to date.

I ran make check (via nix) and did a manual verification, (including a run with Nextcloud) — everything looked good locally. It would be nice if this could get merged.

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants