Support

Admin Tools

#19062 Redundant \r newlines in .htaccess

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by user41246 on Thursday, 06 February 2014 16:30 CST

user41246
 The .htaccess Admin Tools creates contains "\r\n" as new lines.
These "\r" characters are pretty much useless and make the file larger than it needs to be.

I solved this by adding this before line 674 in administrator/components/com_admintools/models/htmaker.php
		$htaccess = str_replace("\r", '', $htaccess);

nicholas
Akeeba Staff
Manager
Hello Peter,

As you can see in administrator/components/com_admintools/models/htmaker.php we do not use \r\n anywhere, just \n. Also if you take a minute to extract our package you will see that the line termination is \n, not \r\n\. I checked with a hex editor to be extra sure, even though I know I am using Mac OS X (with the default line terminator being \n), an IDE that is set up to use the \n line terminator and Git settings which force the line terminator to be \n. However, if you do upload the files via FTP from a Windows machine in ASCII mode then \n is converted to \r\n. That's the difference between ASCII and BINARY transfer modes, actually. Remember that the .htaccess sections are assembled from heredoc blocks in the model, ergo the line termination of the model file is transferred to these lines in .htaccess. Since you are using Windows I can guess how you ended up having \r\n line terminators and, frankly, this has nothing to do with our code.

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

user41246
Sorry, but I know how line terminators work.
This has nothing to do with Windows, as this is happening on the server (SiteGround).

The .htaccess file has say 15,500 bytes when generated. I FTP it to my computer, open it and see all these extra newlines. I remove them in my texteditor. Save it, and the file is 15,000 bytes.

If I add that line to the code as mentioned in initial post, and let AdminTools generate the .htacess: volia, the file is only 15,000 bytes.
If I ftp that file to my computer and open it: no more \r chars.

Having a Windows computer does NOT mean \r chars are added to every file you download or open.

nicholas
Akeeba Staff
Manager
Read what I wrote again. Slowly. Let me write the same thing again, in smaller chunks. Follow me.

The file is generated by the AdmintoolsModelHtmaker Model which lives in administrator/components/com_admintools/models/htmaker.php.

The Model is using the heredoc syntax (the <<<SOMETHING syntax).

The line endings in the heredoc block (ergo: the Model file generating the .htaccess) will of course be reflected in the .htaccess file.

I checked the model file, the path of which I already mentioned, for line endings. Its line endings are \n, NOT \r\n. As I said, I checked with a hex editor. On the very computer used to build the releases you can download from our site.

When you upload (UPload, TO the server – you thought I was talking about DOWNload even though I stated the opposite) a file (I am talking about the htmaker.php Model file) by FTP in ASCII mode from a Windows computer (like yours) the line endings do change from \n to \r\n.

Problem: You have a generated .htaccess file containing \r\n.

The only way this can happen is the Model issuing \r\n line endings in the generated file.

The only way this can happen is the Model containing \r\n line endings.

Our Model, as shipped, does NOT contain \r\n line endings, as I explained.

The only rational explanation is that you uploaded the Model file via FTP in ASCII (or AUTO) mode from your Windows computer.

This means that the Model file now contains \r\n line endings, the opposite of what we ship.

These modified (but NOT by us!) line endings end up in your .htaccess.

Therefore the issue you are reporting is not caused by our software as we ship it.

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

user41246
Ok, read very slowly (same patronizing tone as your reply):

I re-installed AdminTools from a fresh zip (again).
Created the .htaccess and it is full of \r

I don't care f you want to point the finger and not look into it. I'll just fix it on my side every time I generate the .htacess.

Do with the report as you wish.

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!