[Bug]: multiple consecutive spaces in folder name breaks folder access
⚠️ This issue respects the following points: ⚠️
- [X] This is a bug, not a question or a configuration/webserver/proxy issue.
- [X] This issue is not already reported on Github OR Nextcloud Community Forum (I've searched it).
- [X] Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
- [X] I agree to follow Nextcloud's Code of Conduct.
Bug description
I have a folder with a single quote in it ( ' ) and a plus sign in it ( + ) I expected that to be the problem, but when I created a test folder named te+s't there was not any problem in accessing that folder including its test files.
Then I noticed that the problem folder also contained two spaces. I first tested with one space "t e+s't". That also did not result in any problems. But adding a second space after the first one all access to that folder was lost via the web interface and also the desktop client gave errors (I run windows 10 desktop client version 3.14.0)
Steps to reproduce
- create a folder with name "t e+s't" (TWO spces between the 't' and the 'e' !)
- sync via the desktop client
- see the errors mounting..
Expected behavior
I understand two spaces is a bit odd.. but it can happen.. and should work..
Nextcloud Server version
28
Operating system
RHEL/CentOS
PHP engine version
PHP 8.1
Web server
Apache (supported)
Database engine version
MySQL
Is this bug present after an update or on a fresh install?
None
Are you using the Nextcloud Server Encryption module?
None
What user-backends are you using?
- [ ] Default user-backend (database)
- [ ] LDAP/ Active Directory
- [ ] SSO - SAML
- [ ] Other
Configuration report
No response
List of activated Apps
No response
Nextcloud Signing status
No response
Nextcloud Logs
No response
Additional info
I am hesitant to do more testing since I am unable to correct the problem.
I use nextcloud with S3 for data storage. The file id's are there. I simply can't access them. A problem in the DAV connector ?
cc @Pytal also to check if this is an issue on the left side nav bar.
On 28.0.9 everything seems to work fine with two spaces
| Web | Desktop |
|---|---|
Can you provide your logfile @mrAceT? I see that you mention using S3 so that might be related
That might be? I am unable to rename the folder.. I'm stuc with it.. can anyone give me a tip on how to get rid of it?
As mentionedf I use S3, is there a way to edit the database to correct this problem? It also seems to brick the sync with my workstation every now and then.. (also renaming here does not work)
Could you provide the logs @mrAceT?
That's the odd thing.. I don't see any errors regarding this in the nexcloud.log? (or should I set a higher loglevel? (how?) )
You can configure it in config.php, see https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#loglevel
Which loglevel is needed?
>=2 will show warnings which should be sufficient and should be the default
Are you able to delete or rename the folder from the web UI?
No I am not able to do manipulation in any way, not via the web interface, not via the cloud-app on my windows 10
When loglevel is set to 2 I still don't see any warning.. I get the notification it worked.. but it didn't ( I removed the double space)
I am thinking it has something to do with DAV ?
I had this deja-vu feeling.. and thought it might be related to a problem I have had in the past:
https://github.com/nextcloud/server/issues/37852
I performed this "Q&D hack" to see if it would get better.. and.. well.. It seems to bee again/still!? part of the solution (if this popps up everyy now an then, why haven't those three lines entered the production code?), at least now I do get an error in the log (and the renamed message in the image earlier does not show):
when I try to remove one of the two spaces:
could this help?
{"reqId":"ZwhTap4rpXwm1rMxfy1x3gAADQw","level":3,"time":"2024-10-10T22:21:30+00:00","remoteAddr":"1.2.3.4","user":"user","app":"webdav","method":"MOVE","url":"/remote.php/dav/files/user/folder/t%20%0A%20e%2Bs't","message":"File name contains at least one invalid character","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36","version":"29.0.7.1","exception":{"Exception":"OCA\\DAV\\Connector\\Sabre\\Exception\\InvalidPath","Message":"File name contains at least one invalid character","Code":0,"Trace":[{"file":"/folder/cloud.domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/Tree.php","line":95,"function":"getChild","class":"OCA\\DAV\\Connector\\Sabre\\Directory","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/apps/dav/lib/Connector/Sabre/QuotaPlugin.php","line":135,"function":"getNodeForPath","class":"Sabre\\DAV\\Tree","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"beforeMove","class":"OCA\\DAV\\Connector\\Sabre\\QuotaPlugin","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":603,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpMove","class":"Sabre\\DAV\\CorePlugin","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/apps/dav/lib/Server.php","line":383,"function":"exec","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->"},{"file":"/folder/cloud.domain.tld/public_html/remote.php","line":172,"args":["/folder/cloud.domain.tld/public_html/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/folder/cloud.domain.tld/public_html/apps/dav/lib/Connector/Sabre/Directory.php","Line":219,"message":"File name contains at least one invalid character","exception":{},"CustomMessage":"File name contains at least one invalid character"}}
I've been digging:
\lib\private\Files\View.php
throw new InvalidPathException($l->t('File name contains at least one invalid character'));
\lib\public\Files\InvalidCharacterInPathException.php
class InvalidCharacterInPathException extends InvalidPathException { }
\lib\public\Files\InvalidPathException.php
class InvalidPathException extends \Exception {}
I could not find more..
For testing I disabled the error in View.php to see what happens, I get a different error:
{"reqId":"Zw4bd12rfEgPUQIQ51OoIwAAQgI","level":3,"time":"2024-10-15T07:36:23+00:00","remoteAddr":"1.2.3.4","user":"user","app":"webdav","method":"MOVE","url":"/remote.php/dav/files/user/folder/t%20%0A%20e%2Bs't","message":"Exception thrown: OCA\\DAV\\Connector\\Sabre\\Exception\\InvalidPath","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36","version":"29.0.7.1","exception":{"Exception":"OCA\\DAV\\Connector\\Sabre\\Exception\\InvalidPath","Message":"","Code":0,"Trace":[{"file":"/var/www/domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/Tree.php","line":95,"function":"getChild","class":"OCA\\DAV\\Connector\\Sabre\\Directory","type":"->"},{"file":"/var/www/domain.tld/public_html/apps/dav/lib/Connector/Sabre/QuotaPlugin.php","line":135,"function":"getNodeForPath","class":"Sabre\\DAV\\Tree","type":"->"},{"file":"/var/www/domain.tld/public_html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"beforeMove","class":"OCA\\DAV\\Connector\\Sabre\\QuotaPlugin","type":"->"},{"file":"/var/www/domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":603,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/domain.tld/public_html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpMove","class":"Sabre\\DAV\\CorePlugin","type":"->"},{"file":"/var/www/domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/domain.tld/public_html/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/domain.tld/public_html/apps/dav/lib/Server.php","line":383,"function":"exec","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/domain.tld/public_html/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->"},{"file":"/var/www/domain.tld/public_html/remote.php","line":172,"args":["/var/www/domain.tld/public_html/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/domain.tld/public_html/apps/dav/lib/Connector/Sabre/Directory.php","Line":219,"message":"","exception":{},"CustomMessage":"Exception thrown: OCA\\DAV\\Connector\\Sabre\\Exception\\InvalidPath"}}
What caught my eye was the "%0A" I looked that one up and it is a LF > line feed
How in the blazes did that one get there?! I am absolutely certain I tapped the space bar twice upon creating this test (in the web interface).. So somehow, somewhere two consecutive spaces are converted to [space][LF][space] ?
I looked that record up in PHPmyAdmin, I don;t see a [LF]: there?
And I keep getting errors.. how can I get rid of this folder? (it is only a folder with one test file) Could I simply remove the two entries in oc_filecache? and remove the test file in my S3 storage?
I have taken all the precautions I could think of and have removed the two database entries in oc_filecache (the folder and a file) I also removed the corresponding file in S3.. and the immediate problem seems to have been resolved now.. but I'm afraid to start testing again..
An other interesting development regarding this subject:
I had trouble with high server load and checking the logs of Nextcloud I saw that a particular DAV request was flooding the logs.. I discovered that a folder with a double space wasn't able to sync. It took me the better part f this Sunday, but I have found the cause of the Nextcloud bug!
file: /apps/dav/lib/Connector/Sabre/Directory.php
I added:
use function OCP\Log\logger; # at the top of the script
at function: getChild
logger('-')->warning('/lib/private/Files/View:getChild1: mrAceT '.( (!$info)?'!':'' ).' '.$this->path.' | '.$name);
The logs showed:
{"reqId":"aEWDhRM@VXwp5YliYYGG6wAAAVI","level":2,"time":"2025-06-08T12:35:17+00:00","remoteAddr":"1.2.3.4","user":"user","app":"no app in context","method":"PROPFIND","url":"/remote.php/dav/files/user/folder/something%20%C2%A0+something%20-%20something/something","message":"/lib/private/Files/View:getChild1: mrAceT ! /something | something \u00a0+something - something","userAgent":"Mozilla/5.0 bla (Nextcloud, windows-10.0.19045 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"30.0.11.1","data":[]}
Do you see the '\u00a0' !
- That folder was originally created on my Windows computer and was synced with Netxtcloud
- When you search here I have had some sync trouble every now and then. So I can't be sure what effects those sync problems have had the last several years..
- In any case at some point the double space in that folder was logged within Nextcloud as a "space + non-braking-space" !!
- Upon accessing that folder within the web-browser I hgot an error: \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located')
- the folder was gone within the folder on my Windows share
After debugging, more and more I discovered the solution:
file: /lib/private/Files/View.php
at function getFileInfo
I added (immediately after the 'function line'):
$path = preg_replace('/\s/u', ' ', $path);
And the web interface showed me the content of that folder again! And after a bit of fumbling around the desktop client also nicely synced the data again!
PS: as to the performance issue That was not due to this bug.. Just as an index at Nextcloud/mail can have a huge performance increase https://github.com/nextcloud/mail/issues/5985 The same was true for an important piece of my software ;), for fun and education, this is how much adding the correct index can do for better performance:
Just had a bit of a headache tripping over "double spaces" again.. I accessed an old folder containing "FACEBOOK +"
I first thought the plus sign was the trouble maker, but after getting that headache for the last two hours I noticed those two spaces in front of the plus sign.. and I discovered that the second one was a "non braking space character".. Since I was unable to access the over 300 documents in that folder (The S3-file ID's were still there in the bucket, so it was a "reference problem") I needed to figure out a way to get access again.. I'll share here the only solution I could find, for those unlucky ones getting a similar problem:
UPDATE oc_filecache
SET `path` = REGEXP_REPLACE(`path`, 'FACEBOOK[^+]*', 'FACEBOOK '),
`path_hash` = MD5(`path`)
WHERE `path` LIKE 'files/folder/some more/FACEBOOK%;
UPDATE oc_filecache
SET `name` = REGEXP_REPLACE(`name`, 'FACEBOOK[^+]*', 'FACEBOOK ')
WHERE `path` LIKE 'files/folder/some more/FACEBOOK%' AND `fileid` = 252122;
AD: the second query was to also fix the name of the folder
I will immediately admit this isn't pretty, but it did fix my immediate problem of UNaccessible files.
[update] To make the files accessible again via your network drive, rename that folder to something slightly different in the web interface (I removed the 'plus symbol') so that it'll force an update.. otherwise the Query-update will not follow thrugh..
I would so very much appreciate it if Nextcloud would be able to mitigate things like this.. that would prevent me getting headaches over this ;)