[RESOLVED] "Copy Code" bug

Discussion about the board itself, forums organization and site bugs.
Post Reply
Tom T.
Field Marshal
Posts: 3620
Joined: Fri Mar 20, 2009 6:58 am

[RESOLVED] "Copy Code" bug

Post by Tom T. » Mon Dec 14, 2009 3:42 am

viewtopic.php?p=14092#p14092

Bug regarding copying code from within <code> tags.

SeanM wrote:@Giorgio : When I clicked "Select All" on each of the entries, then copied and pasted, each entry was preceded with four (4) spaces (which were subsequently removed). I had not noticed this earlier.

Confirmed, although solved by use of Copy Plain Text, which is my own default for most copying from the Web.

(Note: This add-on is most compatible with Fx 2.x. Extended Copy Menu is better for Fx 3+. Bug and cure confirmed for both browsers with the respective Plain Text copy add-ons.)

Select All > Edit > Copy = [[....addEventListener('DOMContentLoaded',function(){ad_utils.render_ad=function(w)
{w.location=w.location.href.replace(/.*\bTRAILER=([^&]+).*/,'$1')}},true)]]

(I added the double square brackets to make the WYSIWYG content and leading spaces more apparent, and the .... because the forum sw was eliminating all white space beyond a single space.))

Select All > Edit > Copy as Plain Text =
[[addEventListener('DOMContentLoaded',function(){ad_utils.render_ad=function(w)
{w.location=w.location.href.replace(/.*\bTRAILER=([^&]+).*/,'$1')}},true)]]

No leading spaces using either of the Copy as Plain Text methods. Perhaps this should be reported to PHP?

Does anyone here know of a fix that can be implemented locally, or know whether PHPbb Group is aware of this issue?
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5

User avatar
computerfreaker
Senior Member
Posts: 220
Joined: Wed Sep 16, 2009 10:03 pm
Location: USA

Re: "Copy Code" bug

Post by computerfreaker » Mon Dec 14, 2009 8:27 pm

I'm going to guess this is deliberate...
I'm a member on 2 other phpBB3 forums, and each of them has the same "problem". IIRC, the extra spaces are automatically clipped on post submission... if my recollection is correct, that would make this a deliberate feature, probably to keep users from getting the code tag mixed up with the actual code. ;)
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip!
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5

Tom T.
Field Marshal
Posts: 3620
Joined: Fri Mar 20, 2009 6:58 am

Re: "Copy Code" bug

Post by Tom T. » Tue Dec 15, 2009 12:22 am

computerfreaker wrote:I'm going to guess this is deliberate...
I'm a member on 2 other phpBB3 forums, and each of them has the same "problem". IIRC, the extra spaces are automatically clipped on post submission... if my recollection is correct, that would make this a deliberate feature, probably to keep users from getting the code tag mixed up with the actual code. ;)

I'm not following you. The extra spaces were in fact left in when the code was posted, although in some invisible form. But see above: I successfully reproduced the extra-space issue by copying the code with "Select All" > Edit > Copy, then paste into Wordpad. The fact that "Copy as Plain Text" solved the issue indicates that there's some formatting that's putting in the extra spaces.

I'm not understanding how there's any danger of getting the "code" tag, since "Select All" highlights only the code itself.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20

User avatar
computerfreaker
Senior Member
Posts: 220
Joined: Wed Sep 16, 2009 10:03 pm
Location: USA

Re: "Copy Code" bug

Post by computerfreaker » Tue Dec 15, 2009 1:27 am

What I'm saying is like this...

* User hits, say, the "Quote" button
* Quoted post, including code tags, comes up
* If there's no extra spaces, a non-phpBB-savvy user could possibly get the code tag mixed up with the actual code; however, because of the extra spaces, that would be hard to do
* The extra spaces appear to be automatically trimmed out of the code tag upon submission, so IMHO it isn't that big a deal...
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip!
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5

Tom T.
Field Marshal
Posts: 3620
Joined: Fri Mar 20, 2009 6:58 am

Re: "Copy Code" bug

Post by Tom T. » Tue Dec 15, 2009 2:01 am

computerfreaker wrote:What I'm saying is like this...

* User hits, say, the "Quote" button
* Quoted post, including code tags, comes up

But you wouldn't (or shouldn't) copy code from a quote of a post. You should copy it from the actual post in which it was placed -- which was the situation here.
computerfreaker wrote:* The extra spaces appear to be automatically trimmed out of the code tag upon submission, so IMHO it isn't that big a deal...

But they aren't. You don't see them in the slider bar window, true. They're invisible, caused by some sort of formatting which is reproducibly removed by any Plain Text copy add-on. Do what I did and reproduce the issue yourself. And OP SeanM reported this -- in fact, his report was the impetus for this thread.

Try it. Select All > Edit > Copy > paste into, say, Wordpad, and see if it isn't indented four spaces.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20

User avatar
computerfreaker
Senior Member
Posts: 220
Joined: Wed Sep 16, 2009 10:03 pm
Location: USA

Re: "Copy Code" bug

Post by computerfreaker » Tue Dec 15, 2009 6:05 am

computerfreaker wrote:What I'm saying is like this...

* User hits, say, the "Quote" button
* Quoted post, including code tags, comes up

Tom T. wrote:But you wouldn't (or shouldn't) copy code from a quote of a post. You should copy it from the actual post in which it was placed -- which was the situation here.

I finally see what you're getting at. I was thinking of quoting someone else's code, say, to critique it. :oops:

computerfreaker wrote:* The extra spaces appear to be automatically trimmed out of the code tag upon submission, so IMHO it isn't that big a deal...

Tom T. wrote:But they aren't. You don't see them in the slider bar window, true. They're invisible, caused by some sort of formatting which is reproducibly removed by any Plain Text copy add-on. Do what I did and reproduce the issue yourself. And OP SeanM reported this -- in fact, his report was the impetus for this thread.

Try it. Select All > Edit > Copy > paste into, say, Wordpad, and see if it isn't indented four spaces.

I've known about the four-spaces thing for some time (since I joined another phpBB forum almost a year ago), but hadn't thought of it as an issue... however, now that I've properly adjusted my frame of reference to match yours, I see what you're saying. You're right, that's a big inconvenience to anyone trying to move code from a post to an IDE...
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip!
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5

Tom T.
Field Marshal
Posts: 3620
Joined: Fri Mar 20, 2009 6:58 am

Re: "Copy Code" bug

Post by Tom T. » Tue Dec 15, 2009 6:30 am

computerfreaker wrote: I see what you're saying. You're right, that's a big inconvenience to anyone trying to move code from a post to an IDE...

Or in this case, to make a new entry in about:config. Pasting in the string value with the four spaces would invalidate the code. I just tried this with a fake value -- the string value does indeed keep the four blank spaces, surely a deal-killer.

Perhaps first going back to the original thread where this came up, and following the discussion and actions of Giorgio providing code for us to copy and paste into a new about-config value, would have made this more clear, but I'm glad we got it straightened out.

IMHO, the bug report still stands. Cheers. :D
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20

User avatar
Giorgio Maone
Site Admin
Posts: 8697
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: "Copy Code" bug

Post by Giorgio Maone » Tue Dec 15, 2009 11:17 am

Fixed, thanks.
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)

barbaz
Senior Member
Posts: 9145
Joined: Sat Aug 03, 2013 5:45 pm

Re: [RESOLVED] "Copy Code" bug

Post by barbaz » Thu Feb 11, 2016 10:19 pm

This is resolved only for non-syntax-highlighted code

These two code snippets should be identical and thus copy identical.

Working:

Code: Select all

for (var a of window.localStorage.get('dummy')) {
  // do something
}


Not work - not only in the way the OP describes but also added (in my post) a space at the end of the code:

Code: Select all

for (var a of window.localStorage.get('dummy')) {
  // do something
}
*Always* check the changelogs BEFORE updating that important software!
-

Post Reply