mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Fix spec
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/** @babel */
|
||||
|
||||
import url from 'url'
|
||||
|
||||
import {it} from './async-spec-helpers'
|
||||
|
||||
import UrlHandlerRegistry from '../src/url-handler-registry'
|
||||
@@ -13,16 +15,16 @@ describe('UrlHandlerRegistry', () => {
|
||||
registry.registerHostHandler('test-package', testPackageSpy)
|
||||
registry.registerHostHandler('other-package', otherPackageSpy)
|
||||
|
||||
registry.handleUrl("atom://yet-another-package/path")
|
||||
registry.handleUrl('atom://yet-another-package/path')
|
||||
expect(testPackageSpy).not.toHaveBeenCalled()
|
||||
expect(otherPackageSpy).not.toHaveBeenCalled()
|
||||
|
||||
registry.handleUrl("atom://test-package/path")
|
||||
expect(testPackageSpy).toHaveBeenCalledWith("atom://test-package/path")
|
||||
registry.handleUrl('atom://test-package/path')
|
||||
expect(testPackageSpy).toHaveBeenCalledWith(url.parse('atom://test-package/path', true), 'atom://test-package/path')
|
||||
expect(otherPackageSpy).not.toHaveBeenCalled()
|
||||
|
||||
registry.handleUrl("atom://other-package/path")
|
||||
expect(otherPackageSpy).toHaveBeenCalledWith("atom://other-package/path")
|
||||
registry.handleUrl('atom://other-package/path')
|
||||
expect(otherPackageSpy).toHaveBeenCalledWith(url.parse('atom://other-package/path', true), 'atom://other-package/path')
|
||||
})
|
||||
|
||||
it('refuses to handle bad URLs', () => {
|
||||
|
||||
@@ -19,8 +19,9 @@ const {Disposable} = require('event-kit')
|
||||
// `package.json` called "urlHandler". The value of this key should be an object
|
||||
// that contains, at minimum, a key named "method". This is the name of the method
|
||||
// on your package object that Atom will call when it receives a URL your package
|
||||
// is responsible for handling. It will pass the parsed URL as the only argument (by using
|
||||
// is responsible for handling. It will pass the parsed URL as the first argument (by using
|
||||
// [Node's `url.parse(uri, true)`](https://nodejs.org/docs/latest/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost))
|
||||
// and the raw URL as the second argument.
|
||||
//
|
||||
// By default, Atom will defer activation of your package until a URL it needs to handle
|
||||
// is triggered. If you need your package to activate right away, you can add
|
||||
@@ -84,14 +85,15 @@ class UrlHandlerRegistry {
|
||||
}
|
||||
|
||||
handleUrl (uri) {
|
||||
const {protocol, slashes, auth, port, host} = url.parse(uri)
|
||||
const parsed = url.parse(uri, true)
|
||||
const {protocol, slashes, auth, port, host} = parsed
|
||||
if (protocol !== 'atom:' || slashes !== true || auth || port) {
|
||||
throw new Error(`UrlHandlerRegistry#handleUrl asked to handle an invalid URL: ${uri}`)
|
||||
}
|
||||
|
||||
const registration = this.registrations.get(host)
|
||||
if (registration) {
|
||||
registration(url.parse(uri, true))
|
||||
registration(parsed, uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user