Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Configuration File Formatting Oddities: A Short Case Study

0.00/5 (No votes)
5 Jan 2018 1  
URL Encoded Text is URL Encoded Text, wherever you find it, even if it happens to be in and old school Windows INI file.

Introduction

When I discovered that WinSCP wasn’t showing me what I expected to see, I decided to see whether exporting the known good configuration from the old machine would be worth the effort. Anticipating that the configuration included the bookmarks that I saved, half of which (the bookmarks to local directories, all of which moved to a dedicated data volume on the new machine) would need attention before I import them into the copy of WinSCP that’s installed there, I opened the export in my all purpose text editor. I was astonished to see something that I’ve never seen in a Windows configuration file; the Windows paths were URL encoded. The Unix paths weren’t subjected to that indignity.

Background

Fortunately, in this age of online apps for dealing with such matters, I knew exactly where to turn, https://www.urldecoder.org/, which has served me well for quite some time, such as decoding the query strings returned by the Salesforce OAuth API. Since encoded text is encoded text, regardless of the context in which it exists, I used the decoder tab on the application to decode the strings (all in one go), performed a quick find and replace to point them to the corresponding locations on the new machine, then used the encoder tab to encode them before I pasted the updated strings into the configuration file.

Using the Code

Converting the encoded bookmarks was a relatively straightforward process, as shown in the four listings that follow.

0=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_LOGS%5C%2A.%2A
1=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_Tests%5CLoginError%5C%2A.%2A
2=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_Tests%5C%2A.%2A
3=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_Web%5Cetc%5Chttpd%5Cconf.d%5C%2A.%2A
4=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_Web%5Cetc%5C%2A.%2A
5=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5COAuth%5CAWS_Tests%5C%2A.%2A

Listing 1 shows the WinSCP Configuration exported from ENIGMA, the old machine, which I pasted into the Decode tab of the online encoder/decoder app. Listing 2 shows the decoded text.

0=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_LOGS\*.*
1=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_Tests\LoginError\*.*
2=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_Tests\*.*
3=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_Web\etc\httpd\conf.d\*.*
4=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_Web\etc\*.*
5=C:\Users\DAVE\Documents\Praesidium\Building\PCH\OAuth\AWS_Tests\*.*

Listing 2 shows the decoded WinSCP Configuration from ENIGMA, the old machine:, which I copied  from the decoder output window into my text editor. This text was generated from the text shown in Listing 1 by applying the Decode button in the online app, causing the text to appear in the lower text area of the decoder form.

0=F:\Praesidium\Building\PCH\AWS_LOGS\*.*
1=F:\Praesidium\Building\PCH\AWS_Tests\LoginError\*.*
2=F:\Praesidium\Building\PCH\AWS_Tests\*.*
3=F:\Praesidium\Building\PCH\AWS_Web\etc\httpd\conf.d\*.*
4=F:\Praesidium\Building\PCH\AWS_Web\etc\*.*
5=F:\Praesidium\Building\PCH\OAuth\AWS_Tests\*.*

Listing 3 shows the amended WinSCP Configuration for ABACUS, the new machine, which I created by applying a simple find and replace to the five lines shown in Listing 2. This text I pasted into the upper (input) box of the Encoder tab on the online app. Please see the comment in the Points of Interest section that follows.

0=F:%5CPraesidium%5CBuilding%5CPCH%5CAWS_LOGS%5C%2A.%2A
1=F:A%5CPraesidium%5CBuilding%5CPCH%5CAWS_Tests%5CLoginError%5C%2A.%2A
2=F:A%5CPraesidium%5CBuilding%5CPCH%5CAWS_Tests%5C%2A.%2A
3=F:A%5CPraesidium%5CBuilding%5CPCH%5CAWS_Web%5Cetc%5Chttpd%5Cconf.d%5C%2A.%2A
4=F:A%5CPraesidium%5CBuilding%5CPCH%5CAWS_Web%5Cetc%5C%2A.%2A
5=F:A%5CPraesidium%5CBuilding%5CPCH%5COAuth%5CAWS_Tests%5C%2A.%2A

Listing 4 shows the encoded WinSCP Configuration for ABACUS, the new machine, which I copied from the output (lower) text area in the decoder form of the online app, where it appeared after I pasted the text shown in Listing 3 into the input (upper) text area, then pressed the Encode button. This I copied into the configuration file, replacing the text shown in Listing 1. Please see the comment in the Points of Interest section that follows.

Points of Interest

Encoding took two passes, since the first pass, in which I pasted the entire block of text into the input text area of the encoder, produced a single continuous line of output; the line breaks had been stripped. Consequently, it required another pass, in which all but the first four characters of each line, which were not encoded in the configuration that I exported from the old machine, got encoded and pasted back into the text editor.

Neither encoding, nor decoding is technically difficult; they are straightforward one for one text replacements, easily driven by a bidirectional lookup table. Nevertheless, the work is tedious to get right, and simple to program, even in old school JavaScript, of the sort that first appeared in the Netscape Navigator Web browser. It wouldn't surprise me to learn that lots of up and coming programmers are assigned to write such an encoder/decoder application as a school homework assignment.

Nevertheless, it demonstrates the value that lies just a quick Google search away on the World Wide Web of online tools and other resources.

History

Friday, 05 January 2018 was the initial release date.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here