Project

General

Profile

Bug #15244

Method #extname return empty string if filename is dot ('.')

Added by TiSer (Sergey TiSer) 9 months ago. Updated 5 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:89529]

Description

Example 1:

Current behaviour:

File.extname('..jpg')
=> ""

Expected behaviour:

File.extname('..jpg')
=> ".jpg"

Example 2:

Current behaviour:

File.extname('....jpg')
=> ""

Expected behaviour:

=> ".jpg"

History

#1

Updated by TiSer (Sergey TiSer) 9 months ago

  • Description updated (diff)

add one more example

Updated by shevegen (Robert A. Heiler) 9 months ago

Is this a real problem?

How many people have had entries with more leading '.'?

File.extname('foobar......jpg') # => ".jpg"
File.extname('......jpg') # => ""

It's not that I am not inclined to agree about it; I just think
it's a bit strange to want to change that behaviour. Do people
use lots of '.' for names to files or directories or symlinks?

Updated by ahorek (Pavel Rosický) 9 months ago

IMO

File.extname('..jpg')

should be

=> ".jpg"

proposed

=> "."

or the current behaviour

=> ""

makes no sense

#4

Updated by TiSer (Sergey TiSer) 9 months ago

  • Description updated (diff)

Updated by TiSer (Sergey TiSer) 9 months ago

ahorek (Pavel Rosický) wrote:

IMO

File.extname('..jpg')

should be

=> ".jpg"

proposed

=> "."

or the current behaviour

=> ""

makes no sense

Yes, sure. I'm sorry, I oversleep correct cases.
Updated.

Updated by nobu (Nobuyoshi Nakada) 9 months ago

If File.extname("..jpg") returns ".jpg", File.basename("..jpg", ".*") should return "." without that part, to restore the original name from from these results.
It is different from basename(1).

$ basename ..jpg '.*'
..jpg

Updated by TiSer (Sergey TiSer) 8 months ago

This is still present.

Updated by TiSer (Sergey TiSer) 8 months ago

Still present.

Updated by TiSer (Sergey TiSer) 5 months ago

Still present.

Also available in: Atom PDF