SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
38 stars 10 forks source link

__FILE__ returns lowercase even though the files have title and camel case names. But only in the encrypted version of the extension. #130

Open FrancisGerard opened 6 years ago

FrancisGerard commented 6 years ago

SketchUp Pro 2018 OS Platform: Windows 10

My extension WinDoor+ came back as approved from validation but when I tried out the downloaded encrypted code, none of the menus loaded. I checked the value of a module variable I used to collect the names of the extension files as they loaded and found that the encrypted code converted title case names to lower case only. My unecrypted code does not do this. Is this an encryption bug or should I defensively assumed that case sensitivity is not always a given?

This is the code I use to fill an array with the names of files as they load. It is at the end of each file just before the extension module end .

this_file = __FILE__
@files_loaded << File.basename(this_file, File.extname(this_file))

I added a getter method to the module to see what was in @files_loaded and found that all the file names were in lower case in the downloaded version of the extension but not in my unencrypted version.

jeroentheuns commented 6 years ago

Hi, Ruby FILE has a UTF-8 encoding issues. Thomas told us about this during devcamp last week. Maybe ask him as i’m not fully aware of the exact details.

Jeroen

Op 5 okt. 2018 om 08:38 heeft Francis G Mc Shane notifications@github.com het volgende geschreven:

SketchUp Pro 2018 OS Platform: Windows 10

My extension WinDoor+ came back as approved from validation but when I tried out the downloaded encrypted code, none of the menus loaded. I checked the value of a module variable I used to collect the names of the extension files as they loaded and found that the encrypted code converted title case names to lower case only. My unecrypted code does not do this. Is this an encryption bug or should I defensively assumed that case sensitivity is not always a given?

This is the code I use to fill an array with the names of files as they load. It is at the end of each file just before the extension module end .

this_file = FILE @files_loaded << File.basename(this_file, File.extname(this_file)) I added a getter method to the module to see what was in @files_loaded and found that all the file names were in lower case in the downloaded version of the extension but not in my unencrypted version.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Eneroth3 commented 6 years ago

You should always to something similar to this when using __FILE__ to account for non-basic-lating characters in the username.

path = __FILE__
path.force_encoding("UTF-8") if path.respond_to?(:force_encoding)

However that isn't (as far as I can see) related to the constant being all lowercase.

Eneroth3 commented 6 years ago

I've done some testing and it appears __FILE__ isn't defined by the file name on disk but the name the file was loaded by.

Test file:

# D:\Sketchup Plugins\Working Dir\file case\test.rb
p __FILE__

Run from Ruby Console (with SketchUp restart in between calls to require)


load 'D:\Sketchup Plugins\Working Dir\file case\test.rb'
# Prints: "D:\Sketchup Plugins\Working Dir\file case\test.rb"

load 'D:\Sketchup Plugins\Working Dir\file case\TEST.rb'
# Prints: "D:\Sketchup Plugins\Working Dir\file case\TEST.rb"

Sketchup.require 'D:\Sketchup Plugins\Working Dir\file case\test.rb'
# Prints: "D:\Sketchup Plugins\Working Dir\file case\test.rb"

Sketchup.require 'D:\Sketchup Plugins\Working Dir\file case\TEST.rb'
# Prints: "D:\Sketchup Plugins\Working Dir\file case\TEST.rb"

Maybe Sketchup.require makes the path lowercase when loading encrypted files?

EDIT:

I've tested to encrypt the file using the Extension Signature Portal. Files are now named TEST.rbe and TEST.rbs on my disk.

Sketchup.require 'D:\Sketchup Plugins\Working Dir\file case\TEST.rbe'
# Prints: "d:/sketchup plugins/working dir/file case/test.rbe"

Sketchup.require 'D:\Sketchup Plugins\Working Dir\file case\TEST.rbs'
# Prints: "d:/sketchup plugins/working dir/file case/test.rbs"

It appears Sketchup.require makes the whole path lowercase and converts slashes before the Ruby interpreter is told what path to associate the loaded file with, but only for encrypted files.

Using Windows 7, SketchUp 2017.

FrancisGerard commented 6 years ago

Thank you for doing this and for the advice to force UTF-8. It is interesting.

I have decided not to set the array values in my module variable to actual file names as they load. But rather to place a string in the array to represent the file having loaded. This gets away from what the file is called. Sketchup changes the file extension to .rbe when it is encrypted anyway so the name cannot be used without stripping that away.

You are right I think about Sketchp.require and encrypted files.

Eneroth3 commented 6 years ago

What are you using the file names for anyway? Is it a load guard for avoding duplicated menus after plugin reload?

This is what I do for load guard. No file names or other extension specific variable names needed.

Module MyPlugin

  @loaded = false
  unless @loaded
    @loaded = true
    # Do stuff...
  end

end
FrancisGerard commented 6 years ago

Yes, i have 3 different files, each with their own menus, so I need more than just true or false. My @loaded is an array that i place a different string into for each successfully loaded file.

Eneroth3 commented 6 years ago

I would create the whole menu in the same file rather than spreading it out. Even if spread out between files (e.g. different extensions) a wrapping class or module could take care of differentiating the boolean values.

FrancisGerard commented 6 years ago

It works the way it is but I'll think about your suggestion. It is certainly easier to add functionality to the menu if it is in the same file as the extension code.

taustin73 commented 5 years ago

Logged SU-41960