In Valid Logic

Endlessly expanding technology

Torture tests...

Ever want to torture test yourself?  Write some code to resolve a path.  The biggest pain is handling of ".." and "." and intermixing them in ugly requests.

I've been working on updating the Community Server FTP Server to v1.1 and one of the weaknesses I'd found with the previous beta was some of its directory handling.  For v1.1, the server is undergoing some major overhauling (mainly to make it pluggable to work with other apps that might use files/attachments in the future).

I thought I had everything working good, until I decided to try some odder requests.  Like, if in /, typing "cd photos/sample/../sample/../../photos/" should result in changing into /photos/.  You would think that it should be simple, but no.  Had it scanning and counting occurrances of "..", but it was looking only for consequtive ones, and then removing them all.  So it would count 2 occurrances (starts from the end back), and them remove the next two references.  It wasn't paying attention to the fact that one of the instances it is removing might be another "..".  So had to change it to check them while removing and not removing too much or too little.

Then I decided to start testing the "." current directory item.  From /photos/, typing "cd ./../photos/sample/.././../" should result in /.  But again, nope.  When removing instances of "..", it was treating "." as a valid entry it should remove and count as occurance, when it should remove it and not count it as an occurance.  Then you get into cases where you index gets out of range and you throw an exception before it has processed all of it.  Oy.

In short, it has been a painful past two hours.  I finally got it working and all of my test cases are passing.  Yay.  I've fired up the debugger so many times that Visual Studio has frozen on me twice.  Just thought I'd share some excitement from my day.

Tuesday, May 24, 2005

blog comments powered by Disqus