-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
{J,CS}SResourceLocator: account for symlinks in app path #7061
{J,CS}SResourceLocator: account for symlinks in app path #7061
Conversation
Currently, if the app path includes a symlink, the calculated webDir will be incorrect when generating CSS and URLs will be pointing to the wrong place, breaking CSS. Use realpath when retrieving app path, and these issues go away. Fix nextcloud#6028 Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
8a2a077
to
b0d2966
Compare
I'd love to cover this in a test if anyone can point me in the right direction. |
Codecov Report
@@ Coverage Diff @@
## master #7061 +/- ##
============================================
+ Coverage 50.73% 50.76% +0.02%
Complexity 24412 24412
============================================
Files 1579 1579
Lines 93321 93323 +2
Branches 1359 1359
============================================
+ Hits 47348 47375 +27
+ Misses 45973 45948 -25
|
|
I guess we need the same for the JSCombiner? |
Is this related to #5289? |
I guess you could write a unit test for that with creating a symlink using http://php.net/manual/en/function.symlink.php. It seems that the CSSResourceLocator class is not unit-tested at all: https://github.com/nextcloud/server/tree/master/tests/lib/Template |
I'm not sure. It's certainly possible. |
@MorrisJobke I'm assuming you're talking about the JSResourceLocator? Assuming so, I've pushed that change here as well. @juliushaertl I've also pushed tests for both JSResourceLocator as well as CSSResourceLocator that cover the functionality introduced here. I assume they're run automatically in CI, right? Or do I need to alter another file somewhere? |
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
8e3e053
to
06ba1a8
Compare
They run automatically (if they are located in a tests/ folder), but cause a Fatal error:
|
ab14ffd
to
5a69f9b
Compare
This seems to be the only way to have the same helpers used between tests in a manner that works for both standalone phpunit and autotest.sh. Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
5a69f9b
to
9c24b7b
Compare
Thanks @MorrisJobke, all fixed up and ready for review. |
@kyrofa Do you have some steps to reproduce the issue/test the pr? Symlinking the apps folder doesn't cause the issue on my setup. |
Sure thing @juliushaertl. Note that while the fix is done in the ResourceLocators, the bug doesn't bite until CSS is generated (which is then cached). The problem isn't quite as simple as "app paths with symlinks don't work", the app path in question actually needs to be within a webroot that is a symlink, so let's use the default apps as an example.
Now you've set things up such that:
Go ahead and install Nextcloud now, and you'll see things like this: |
// Account for the possibility of having symlinks in app path. Doing | ||
// this in a separate variable, because an empty argument to realpath | ||
// gets turned into cwd, which makes it hard to see if app_path got set. | ||
$real_app_path = realpath($app_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also do this after the check if the app_path is empty like it is done in in the CSSResourceLocator? Otherwise $real_app_path still might be the working directory for empty app paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the diff is hiding that from you, expand is a little below this. It's done here. I believe it's done after looking for l10n because those should be able to not exist without raising errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this will cause weird behavior with using the cwd for l10n, huh. I refactored it just a tad to account for that, and pushed it up. It means we need to check twice, but I don't see a straight-forward way around that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just move the check got app_path and app_url in front of the realpath call? That way we don't append any js sources at cwd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but not without changing the l10n
behavior. I don't claim to be an expert in the code, of course, but right now it seems that if a l10n
file doesn't exist, the error is ignored. If we move the check above that logic, we start raising an error instead. Are we wanting that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok, makes sense to keep it like this i guess. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kyrofa I could reproduce it and your fix works great for that.
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
The failed unit test is unrelated. |
Can we get this back into stable12 as well? It's the last remaining issue for the snap. |
Could you open a backport to the stable12 branch as PR? |
Sure thing! #7170 |
Currently, if the app path includes a symlink, the calculated webDir will be incorrect when generating CSS and URLs will be pointing to the wrong place, breaking CSS.
This PR fixes #6028 by using realpath when retrieving app path, which makes these issues go away.