Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fix #4333 (Files incorrectly identified as plain text if folder's name has got the "#" char) #4379

Merged
merged 13 commits into from
Jul 16, 2013

Conversation

busykai
Copy link
Contributor

@busykai busykai commented Jul 4, 2013

Replaced usage of PathUtils (inappropriate for the task) with new FileUtils.getBaseName. JSDoc and unit tests included.

- Added FileUtils.getBaseName (jsdoc and unit tests included).
- Replace usage of path-utils.js with getBaseName.
@busykai
Copy link
Contributor Author

busykai commented Jul 4, 2013

I also suggest that NativeFileSystem.Entry constructor (which is used to display base names in the project side bar) also takes advantage of the same FilUtils.getBaseName() facility. Currently, it's using splits path by separator and then iterates until the last name to get the base name for an entry. I intentionally programmed getBaseName so that it would support directories as well.

Related to issues adobe#3269, adobe#4210.
Based on the discussion and suggestions in adobe#3310.

If a project has a .jslint.json in its root, it gets loaded and passed to each
JSLint run within the project. The configuration file gets reloaded each time
it is saved or refreshed.
@ghost ghost assigned RaymondLim Jul 8, 2013
@njx
Copy link
Contributor

njx commented Jul 8, 2013

To @RaymondLim

@peterflynn
Copy link
Member

Yikes, this suggests to me that we should never use PathUtils to parse local paths -- I bet this isn't the only place where a "#" in a file/folder name breaks stuff. It seems only safe to use PathUtils on things that are actually true URLs.

I see potentially unsafe uses in DocumandCommandHandlers, JSUtils, FileIndexManager, and UrlCodeHints/main. Should we file a new bug for all that, or try to tackle them here?

Also, some unit tests of the actual affected functionality (e.g. LanguageManager APIs) are probably a good idea...

@njx
Copy link
Contributor

njx commented Jul 9, 2013

Yes, PathUtils is a misnomer--it should really be called URLUtils. But we didn't write it so we can't change the name :)

I think it would be good to fix all of them at once if it's relatively straightforward to do so.

@busykai
Copy link
Contributor Author

busykai commented Jul 10, 2013

I can review the code for misuse of PathUtils. Should I file an issue?

@busykai
Copy link
Contributor Author

busykai commented Jul 11, 2013

Here is the report on usage of PathUtils in entire brackets codebase:

OK -- uses PathUtils properly or has no impact:
    1 ./.jshintrc
          OK -- in globals
    2 ./src/LiveDevelopment/Agents/CSSAgent.js
          OK -- parses URL
    2 ./src/help/HelpCommandHandlers.js
          OK -- parses URL
    2 ./src/preferences/PreferencesDialogs.js
          OK -- parses URL
    2 ./src/utils/UpdateNotification.js
          OK -- parses URL
    4 ./src/extensibility/Package.js
          OK -- parses URL
    36 ./test/perf/OpenFile-perf-files/brackets-concat.js
          OK -- testcase input file

Has to be fixed:
    1 ./src/brackets.js
          Clean up - jslint config
    1 ./src/document/Document.js
          Clean up - jslint config
    1 ./src/document/DocumentManager.js
          Clean up - jslint config
    1 ./src/extensibility/InstallExtensionDialog.js
          Clean up - jslint config
    1 ./src/search/FindInFiles.js
          Clean up - jslint config
    1 ./test/SpecRunner.js
          Clean up - jslint config
    2 ./src/extensions/default/QuickView/main.js
          OK -- parses URL
          Fix -- use dirName
    2 ./src/extensions/default/UrlCodeHints/main.js
          Fix -- use dirName
    2 ./src/language/JSUtils.js
          Fix -- uses to get file extension
    2 ./src/project/FileIndexManager.js
          Fix -- uses to get file extension
    4 ./src/document/DocumentCommandHandlers.js
          Fix -- use baseName, dirName

In order to fix this, two more methods corresponding to the usage of PathUtils have to be added: getDirectoryName (analogous to dirname(1)) and getFileExtension. I will amend this pull request.

@busykai
Copy link
Contributor Author

busykai commented Jul 12, 2013

This pull request is no good as is. Hold on until I update it, please.

The tests assumed that CodeMirror modes are loaded at the time of test
definition.
Conflicts:
	src/file/FileUtils.js
@busykai
Copy link
Contributor Author

busykai commented Jul 14, 2013

I need your advice: what is normally done when the unit tests starts failing because of loading sequence/timing has changed due to a fix?

I found that the fix is causing some unit tests to fail. I specifically looked into CSSUtils and found (after some banging my head against the wall) that the 43885a6 is changing the load sequence, so b87f6a0 fixes it.

The other tests that are failing are trickier... For example some EditorCommandHandler tests do not have Commands loaded at the time of execution. One fails with "cannot read property EDIT_DELETE_LINES of null", for example. When re-ran on its own, it passes. I'm going to resolve all these, but please let me know what you think...

@busykai
Copy link
Contributor Author

busykai commented Jul 14, 2013

Nevermind the comment on EditorCommandHandler tests, it's a separate issue #4451. There's a pull request to fix it too.

This pull request also breaks DocumentCommandHandler tests in the same fashion #4437 does. Applying #4448 fixes them (I observe only two failures while #4448 fixes three).

LanguageManager.getLanguageForPath should not use URLs. Instead, it
should use local filesystem paths.
Also:
Remove leftover reference to LanguageManager from FileUtils.
Use existing code to implement getBaseName.
Implementation changed to use FileUtils.getBaseName and
FileUtils.getFilenameExtension.
// verify editor content
var mode = LanguageManager.getLanguageForPath("http://only.org/testing/the/path.css?v=2").getMode();
var mode = LanguageManager.getLanguageForPath("/only/testing/the/path.css").getMode();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a hypothetical test case. LanguageManager is used strictly to operate on local files. I think it was inspired by the fact that PathUtils was used to parse the file path in the first place.

@busykai
Copy link
Contributor Author

busykai commented Jul 14, 2013

@RaymondLim @njx @peterflynn this is ready for review. Ended up being not quite starter bug. :)

@RaymondLim
Copy link
Contributor

@busykai

I'll be reviewing and running your unit tests soon. In the meantime, could you please sign up CLA here?

@adrocknaphobia
Copy link
Contributor

@RaymondLim : @busykai is covered under the corporate CLA we have for Intel.


/**
* Get the base name of a file or a directory.
* @param {string} full path to a file or directory
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add fullPath right after {string}.

*
* @param {string} full path to a file or directory
* @return {string} Returns the extension of a filename or empty string if
* the argument is a directory
Copy link
Contributor

Choose a reason for hiding this comment

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

Append or a filename with no extension. to this line so that we have more accurate description.

@busykai
Copy link
Contributor Author

busykai commented Jul 15, 2013

Thank you @adrocknaphobia ! I wasn't sure what's the right way to clarify this.
@RaymondLim -- fixed as per your comments.

@RaymondLim
Copy link
Contributor

Looks good. Merging.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants