CfsPath>>#components infinite recursion

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

CfsPath>>#components infinite recursion

Gabriel Cotelli
Hi,

I think I found a bug in the reference method (I'm using VA 8.0.3 but
the bug is present in another versions too).

Try (on a Windows machine):
        (CfsPath named: 'c:\This\Is\A\Test\File.txt') components.
        (CfsPath named: '.\This\Is\A\Test\File.txt') components.
        (CfsPath named: 'This\Is\A\Test\File.txt') components

The first expression leads to an infinite recursion (the last 2 worked
ok for me).

This is the original method implementation:
components
        "Answer an array of paths representing the paths
        specified by @pathName.  For example, the pathname
        This\Is\A\Test\File.txt will return the following paths:

                This
                This\Is
                This\Is\A
                This\Is\A\Test
                This\Is\A\Test\File.txt

        The paths will be ordered hierarchically."

        | result directory |

        result := OrderedCollection with: self.
        directory := self directory.
        [directory notNil] whileTrue: [
                result addFirst: directory.
                directory := directory directory].
        ^result asArray

Doing the following change works Ok (at least for the shown examples):

components
        "Answer an array of paths representing the paths
        specified by @pathName.  For example, the pathname
        This\Is\A\Test\File.txt will return the following paths:

                This
                This\Is
                This\Is\A
                This\Is\A\Test
                This\Is\A\Test\File.txt

        The paths will be ordered hierarchically."

        | result directory parent |

        result := OrderedCollection with: self.
        directory := self.
        parent := self directory.
        [parent notNil and:[parent ~= directory]] whileTrue: [
                result addFirst: parent.
                directory := parent.
                parent := directory directory].
        ^result asArray

I don't know if this retains exactly the same semantics, so please
review before inclusion.

Regards,
Gabriel

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/va-smalltalk?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: CfsPath>>#components infinite recursion

John O'Keefe-3
Gabriel -

Yes, this method is certainly broken.

What would you expect to be the result of evaluating:
((CfsPath named: 'c:\This\Is\A\Test\File.txt') components) at: 1.
Should it be 'c:/' or 'This'?

And the result of evaluating: 
((CfsPath named: '.\This\Is\A\Test\File.txt') components) at: 1.
Should it be '\' or '.' or 'This'?

And the result of evaluating: 
((CfsPath named: '..\This\Is\A\Test\File.txt') components) at: 1.
Should it be '\' or '..' or 'This'?

And the result of evaluating: 
((CfsPath named: '\This\Is\A\Test\File.txt') components) at: 1.
Should it be '\' or 'This'?

John 
 
 

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/va-smalltalk?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: CfsPath>>#components infinite recursion

Gabriel Cotelli
Hi John,
I'm not using this method in the code so I have some doubts about the expected semantics. Just found the bug running some code snippet. 
 
My best guess is:

What would you expect to be the result of evaluating:
((CfsPath named: 'c:\This\Is\A\Test\File.txt') components) at: 1.
Should it be 'c:/' or 'This'?

'c:' on Windows

And the result of evaluating: 
((CfsPath named: '.\This\Is\A\Test\File.txt') components) at: 1.
Should it be '\' or '.' or 'This'?

'.' on Windows

And the result of evaluating: 
((CfsPath named: '..\This\Is\A\Test\File.txt') components) at: 1.
Should it be '\' or '..' or 'This'?

'..' on Windows

And the result of evaluating: 
((CfsPath named: '\This\Is\A\Test\File.txt') components) at: 1.
Should it be '\' or 'This'?

Raise an exception in Windows (IMHO this isn't a valid file path)
'\This\Is\A\Test\File.txt' in Unix (because is a valid file name, no directories involved here) 

Regards
Gabriel

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/va-smalltalk?hl=en.