Make WordPress Core

Opened 9 years ago

Last modified 3 years ago

#9716 reopened defect (bug)

WordPress Theme/Plugin editor adds blank lines — at Version 14

Reported by: Vistronic Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.7.1
Component: Administration Keywords: has-patch needs-testing
Focuses: Cc:

Description (last modified by SergeyBiryukov)

When I edit theme css in theme editor in WP admin WordPress reformats my CSS and adds a blank life between entrys in css. it adds a cr and line break .... In other words if you have a 100 line css download with FTP look at in text editor it is now 200 lines as WP added blank lines to css it should not be adding things to the CSS?

It may only do this when it wraps window but I think not it appears to add blank lines.

Imagine the damage to a 1000 line CSS it spaces every entry by 1 line!!!!!!!!!!!!!! It stiil works but it messes it up.


Here is part of the problem but not the double space in total. When you down load the file in FTP and it is in windows encoding the line endings. So you ftp back and all is fine. Now you are at the coffee shop and what a quick change, so you login to WP admin and theme editor edit CSS. Now you get home and download in ftp to continue your work on CSS. The file is now mac formatted (or thinks it is) so when you edit the line endings do not contain the right line breaks for windows OR WP theme editor as it ignores them. This explains the wierd spacing though not the double spacing .... why is it converting to mac and yet ignores mac?! weird.. it adds a CR tag must be bug again though its still double spacing on edit IN windows line ending though if you down load cSS its tagged mac format...

Use notepad 2 or Note pad plus to see the error. When ever you edit with WordPress editor it adds cr and says css is now mac formatted.

FTP download the file and now see all the extra CR's it adds.

So it likes CR only so I convert to CR only and it beaks CSS it wants CR LF to work but if that is the case why does the online editor add CR only?????????????????????????

Change History (16)

#1 @azaozz
9 years ago

  • Resolution set to invalid
  • Status changed from new to closed

WordPress 2.7.1 doesn't have CSS editor, it has file editing capabilities using a textarea where everything is controlled by your browser. If you're having problems try another browser or file a bug with the browser's creators.

If you were testing WordPress 2.8 which includes CodePress, the proper place for bug reports would be CodePress' bug tracker.

#2 @Denis-de-Bernardy
9 years ago

  • Milestone Unassigned deleted

#3 @harmr
7 years ago

  • Cc harmr added
  • Component changed from General to Editor
  • Keywords needs-refresh needs-testing added; CSS removed
  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Summary changed from Wordpress Theme editor adds CR tag and Mac format CSS file to Wordpress Theme/Plugin editor adds blank lines
  • Version changed from 2.7.1 to 3.2.1

The reported problem still exists´(and isnt limited to editing css files). I´ve been struggling for years with this bug and havent found a solution yet. When saving theme or plugin files via Wordpress backend editor, blank lines are added after each line - which on the other hand are only seen, if I open the file via Dreamweaver or ftp/download. I then have to do a reg-ex-search and replace to get them removed (find: [\r\n]{2,} replace with: \n )

#4 @duck_
7 years ago

  • Keywords editor needs-refresh needs-testing removed
  • Milestone set to Awaiting Review

Moving to Awaiting Review as the blank milestone is putting this in report/5 (i.e. for 3.3).

6 years ago

Give the user option of line endings

#5 @kurtpayne
6 years ago

  • Cc kpayne@… added
  • Keywords has-patch added

#6 @kurtpayne
6 years ago

  • Keywords reporter-feedback added

9716.patch may not undo the "double line" problem you're seeing, harmr. The file is read off the file system (using file_get_contents), presented in the browser (very dependent upon your browser + OS), then posted back to the server, and written back using fopen/fwrite.

Somewhere in that process, the line endings are being translated incorrectly. WordPress is using common practices for working with text files in the web, but this patch should give you a choice as to how the line endings are translated when they written back to the server. The fopen mode in the patch has been changed, too, to prevent any unexpected EOL translation.

There's some conflicting notes on the fopen documentation page about using 't' and 'b' modes depending on your goals.

Please report back if this helps resolve the problem going forward, introduces new problems, undoes the old "double line" problem in existing files, etc.

#7 follow-up: @SergeyBiryukov
6 years ago

  • Version changed from 3.2.1 to 2.7.1

Version number indicates when the bug was initially introduced/reported.

Replying to harmr:

When saving theme or plugin files via Wordpress backend editor, blank lines are added after each line - which on the other hand are only seen, if I open the file via Dreamweaver or ftp/download.

Sounds like Dreamweaver doesn't autodetect EOL properly. Could you describe the steps (including environment) to reproduce the addition of blank lines?

#8 @helenyhou
6 years ago

#20244 closed as duplicate.

#9 in reply to: ↑ 7 @azaozz
6 years ago

Replying to SergeyBiryukov:

Sounds like Dreamweaver doesn't autodetect EOL properly...

Seems line breaks have to be normalized when saving edited files. Also if line breaks are \r, the theme or plugin "header" becomes inaccessible. This is browser and OS dependent but seems all modern browsers work with \n line breaks in a textarea. So the patch can be as simple as:

srt_replace( array("\r\n", "\r"), "\n", $content );

Related #20248

Last edited 6 years ago by azaozz (previous) (diff)

#10 @nacin
6 years ago

When we do that, we can cause problems if someone then opens up the file on their local OS.

If someone were to open a \n-normalized file in Notepad, when it was originally \r\n, it's a bad experience. I dealt with this in GSoC two years ago but didn't come up with a great solution. We need to make sure the file displays fine but saves with the existing endings.

#11 @mbijon
6 years ago

  • Cc mike@… added

#12 @HallMarc
6 years ago

  • Cc HallMarc added
  • Keywords needs-patch added; has-patch removed

I have found a way to normalize the contents before they get written back to the file. In both wp-admin/theme-editor.php and wp-admin/plugin-editor.php you need to change one line of code:


	$newcontent = stripslashes($_POST['newcontent']);

And replace it with this:

	$newcontent = ereg_replace("\r\n?", "\n", stripslashes($_POST['newcontent']));

And all is well. I hope this gets included in the next update. Since I am unsure as of yet as to why the extra CR gets added or when; the ability for the end-user to turn this on/off may be a good addition.

Last edited 6 years ago by HallMarc (previous) (diff)

#13 @HallMarc
6 years ago

  • Keywords needs-patch removed

@SergeyBiryukov - Thank you for updating what I posted to a non-deprecated function. Although IMHO I would use preg-replace instead of str-replace as the first is for reg exp.

	$newcontent = preg_replace("(\r\n|\r|\n\r)","\n",stripslashes($_POST['newcontent']));

@Everyone - Curious if this will be the one fix we need. Both solutions have worked for me without causing any funkiness when opening the file after a WP edit in any program; Dreamweaver, Sublime Text 2, Windows Notepad and WordPad included. If this patch works across all platforms *nix/Windows then we won't need the toggle option.

Last edited 6 years ago by HallMarc (previous) (diff)

#14 @SergeyBiryukov
6 years ago

  • Description modified (diff)
  • Keywords has-patch needs-testing added; reporter-feedback removed
  • Milestone changed from Awaiting Review to Future Release
  • Summary changed from Wordpress Theme/Plugin editor adds blank lines to WordPress Theme/Plugin editor adds blank lines
Note: See TracTickets for help on using tickets.