atxgeek 


just one more geek in a sea of austin techies

June 26, 2014

Windows Clipboard: Remove Trailing Space #WindowsGeek

It seems I can barely go more than a week or two without encountering a certain windows-related copy-and-paste issue.  The issue? Unwanted trailing spaces.  The culprit?  Windows' rendering for text highlighting.

Figure 1 -- It's hard to tell if your highlighted text
includes an unwanted training space.
When highlighting text to copy, Windows will sometimes include a trailing blank space character as part of your selection if one happens to follow the last word selected.  When this does happen it is often impossible to spot (see Figure 1).

This issue is especially nefarious when it comes to troubleshooting:  a typical visual check won't catch text that includes a trailing space versus the expected value (no trailing space).

What to do?  Windows' clipboard is simply performing the one simple task it was created to do.  We can't make the Windows clipboard smarter but we can substitute in a smarter option...


The Sneaky Trailing Space:  Hard to Spot
Even in a serious admin tool like SQL Server Management Studio trailing spaces can't be detected from simply looking at read-only results.  You either need to craft a SQL query to filter for results with trailing spaces (this is probably the best way) or view a table in edit mode and highlight each value to see which value exhibits a bit of extra highlighting following the text.

Figure 2 shows a database read-only view and an edit view for the same table.  It's apparent how trailing spaces can easily go undetected.

Figure 2: SQL Server Management Studio -- Can you spot the trailing space?
Even with "Manager" selected the highlighted trailing space is not overly apparent.

Figure 3:  DNN Security Role Names
Trailing spaces are allowed (?!?)
Another place trailing spaces can cause mischief is in application configurations.  I've blogged about DotNetNuke (DNN) before and how it still retains some head-scratching issues despite considerable improvement over the past decade. One issue is that DNN allows you to define a security role name with a trailing space. You'd think that would have been fixed years ago when the first Active Directory integration option was introduced into the DNN core code.  (Explanation:  AD integration works by pairing AD group names with DNN security role names and Active Directory specifically disallows trailing spaces in critical object names.)


What's the Fix?
Ok, point made:  trailing spaces are bad and Windows' copy-and-paste feature (i.e., the clipboard) does nothing to help me avoid them.  Fortunately we are not required to stick with the default clipboard.  Enter the  Outertech Clipboard Manager.  Like most other 3rd party clipboard alternatives the Clipboard Manager saves multiple recent copies -- your 20 most recent copies, in fact.  Unlike most other clipboard alternatives, though, Clipboard Manager also provides the option to automatically trim trailing spaces.  Aha!


Figure 4:  The Outertech Clipboard Manager (free) allows you to
automatically remove trailing spaces in your copy-and-paste operations.

To be fair there are two downsides to this free tool.  First, this clipboard alternative only works for text-based content.  That means you're still stuck with CTRL-V for pasting images.  The second downside is that you need to get used to using a different key for pasting.  On the other hand, the program allows you to pick your own key combination so you do have options (except for overriding the default CTRL-V paste command -- Windows won't let you reassign that).

One excellent feature is the ability to define permanent ("sticky") clips.  That is, besides your 20 most recent copied items, you can also predefine up to 20 more items that are always ready to be pasted.  You can also have the program remove any carriage returns / line breaks from copied links that span multiple lines.  Those of you who have been confounded by this in the past know what I'm talking about.  The rest of you have just been lucky.


Summary
Switching to a trailing-space-trimming-clipboard-tool still won't solve the trailing space issue as it won't address trailing spaces added from other people/systems.  It will, however, help *you* to avoid being responsible for propagating unwanted trailing spaces.



No comments:

Post a Comment