Skip to content

Geshi/ExtEnscript: Treats file-extensions case-insensitively#201

Closed
danielmarschall wants to merge 5 commits intowebsvnphp:masterfrom
danielmarschall:patch-1
Closed

Geshi/ExtEnscript: Treats file-extensions case-insensitively#201
danielmarschall wants to merge 5 commits intowebsvnphp:masterfrom
danielmarschall:patch-1

Conversation

@danielmarschall
Copy link
Copy Markdown
Contributor

The Geshi highlighting does not work with files which have upper-case file extensions, for example PROJECT.PAS (upper case because it is a DOS retro-coding project) is not detected as TurboPascal/Delphi file.
This PR solves the problem.

foreach ($extGeshi as $language => $extensions) {
if (in_array($filename, $extensions) || in_array($ext, $extensions)) {
$extensions_lc = array_map('strtolower', $extensions);
if (in_array(strtolower($filename), $extensions_lc) || in_array(strtolower($ext), $extensions_lc)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so complicated? extGeshi will stay canonically lowercase and $ext will be lower-cased?

Off topic: I wonder then this will return true:

in_array($filename, $extensions)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code fror content type detection does not probe for the entire filename.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line in question:

./filedetails.php:$extn = strtolower(strrchr($path, '.'));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off topic: I wonder then this will return true:

in_array($filename, $extensions)

Hm... Just a theory: MAKE files don't contain a classical filename extension. But they can be identifiered using their name "Makefile", so I guess in this case, we would need to add "Makefile" to the GeShi extensions.

Why so complicated? extGeshi will stay canonically lowercase and $ext will be lower-cased?

Yes, that is indeed easier. But personally I feel safer when both sides are lower-cased before comparing them. Back to my example, it's possible that people add "Makefile" to extGeshi, and they might be very frustrated because it doesn't work anymore (or is WebSvn converting extGeshi to all-lower-case somewhere in the program flow?).


in regards filedetails.php it looks like $extn is forced lower-case and then used at two instances:

  • in_array($extn, $zipped)
  • $contentType[$extn]

In this case I also want to become independent of case-sensitivety, so I would prefer to change:

  • Don't force $extn to be lower-case
  • in_array($extn, $zipped) => i would also like to compare case-insensitively
  • $contentType[$extn] => search for the (first) element in the array, indepdenent of the case

What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off topic: I wonder then this will return true:

in_array($filename, $extensions)

Hm... Just a theory: MAKE files don't contain a classical filename extension. But they can be identifiered using their name "Makefile", so I guess in this case, we would need to add "Makefile" to the GeShi extensions.

Why so complicated? extGeshi will stay canonically lowercase and $ext will be lower-cased?

Yes, that is indeed easier. But personally I feel safer when both sides are lower-cased before comparing them. Back to my example, it's possible that people add "Makefile" to extGeshi, and they might be very frustrated because it doesn't work anymore (or is WebSvn converting extGeshi to all-lower-case somewhere in the program flow?).

I agree on Makefiles, I have just tried. There is no mapping and it works exactly that way. I am revoking my comment for the entire file. More than that, I would not lowercase the whole filename because of cases like Makefile and CMakeLists.txt.

in regards filedetails.php it looks like $extn is forced lower-case and then used at two instances:

* in_array($extn, $zipped)

* $contentType[$extn]

In this case I also want to become independent of case-sensitivety, so I would prefer to change:

* Don't force `$extn` to be lower-case

* in_array($extn, $zipped) => i would also like to compare case-insensitively

* $contentType[$extn] => search for the (first) element in the array, indepdenent of the case

What do you think?

Hmm, lowercasing the entire filename looks wrong to me. Makefile != makefile in terms of any make implementation. I wouldn't touch it.

So for the same of simplicity I still prefer:

if (in_array($filename, $extensions) || in_array(strtolower($ext), $extensions)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have applied the changes. But I think we really need to add a hint to the documentation that $contentType,
$zipped, and $extGeshi must only contain lower-case entries.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have applied the changes. But I think we really need to add a hint to the documentation that $contentType, $zipped, and $extGeshi must only contain lower-case entries.

I agree, please make a separate PR for the doc change.

@michael-o michael-o self-requested a review November 10, 2023 19:22
Copy link
Copy Markdown
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still prefer to keep this as simple as possible.

@danielmarschall danielmarschall changed the title Geshi treats file-extensions case-insensitivity now Geshi/ExtEnscript: Treats file-extensions case-insensitively Nov 13, 2023
@michael-o michael-o closed this in 2717b1b Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants