Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
11fcaf8d
Commit
11fcaf8d
authored
Aug 28, 2018
by
Roman Yurchak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw error on invalid packages
parent
c9d5ba3c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
15 deletions
+22
-15
src/pyodide.js
src/pyodide.js
+7
-7
test/conftest.py
test/conftest.py
+2
-1
test/test_package_loading.py
test/test_package_loading.py
+13
-7
No files found.
src/pyodide.js
View file @
11fcaf8d
...
...
@@ -3,7 +3,7 @@
*/
// Regexp for validating package name and URI
var
package_name_regexp
=
'
[a-z0-9_
\
-]+
'
var
package_name_regexp
=
'
[a-z0-9_
][a-z0-9_
\
-]*
'
var
package_uri_regexp
=
new
RegExp
(
'
^https?://.*?(
'
+
package_name_regexp
+
'
).js$
'
,
'
i
'
);
var
package_name_regexp
=
new
RegExp
(
'
^
'
+
package_name_regexp
+
'
$
'
,
'
i
'
);
...
...
@@ -44,8 +44,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
const
package
=
_uri_to_package_name
(
package_uri
);
if
(
package
==
null
)
{
console
.
log
(
`Invalid package name or URI '
${
package_uri
}
'`
);
break
;
throw
new
Error
(
`Invalid package name or URI '
${
package_uri
}
'`
);
}
else
if
(
package
==
package_uri
)
{
package_uri
=
'
default channel
'
;
}
...
...
@@ -54,9 +53,10 @@ var languagePluginLoader = new Promise((resolve, reject) => {
if
(
package
in
loadedPackages
)
{
if
(
package_uri
!=
loadedPackages
[
package
])
{
console
.
log
(
`Error: URI mismatch, attempting to load package `
+
`
${
package
}
from
${
package_uri
}
while it is already `
+
`loaded from
${
loadedPackages
[
package
]}
!`
);
throw
new
Error
(
`URI mismatch, attempting to load package `
+
`
${
package
}
from
${
package_uri
}
while it is already `
+
`loaded from
${
loadedPackages
[
package
]}
!`
);
}
}
else
{
toLoad
[
package
]
=
package_uri
;
...
...
@@ -67,7 +67,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
}
});
}
else
{
console
.
log
(
`Unknown package '
${
package
}
'`
);
log
.
console
(
`Unknown package '
${
package
}
'`
);
}
}
}
...
...
test/conftest.py
View file @
11fcaf8d
...
...
@@ -40,7 +40,8 @@ def _display_driver_logs(browser, driver):
elif
browser
==
'firefox'
:
# browser logs are not available in GeckoDriver
# https://github.com/mozilla/geckodriver/issues/284
print
(
'Cannot access browser logs for Firefox.'
)
print
(
'Accessing raw browser logs with Selenium is not '
'supported by Firefox.'
)
class
SeleniumWrapper
:
...
...
test/test_package_loading.py
View file @
11fcaf8d
import
pytest
from
selenium.common.exceptions
import
WebDriverException
def
test_load_from_url
(
selenium_standalone
,
web_server
):
...
...
@@ -16,15 +18,19 @@ def test_load_from_url(selenium_standalone, web_server):
def
test_uri_mismatch
(
selenium_standalone
):
selenium_standalone
.
load_package
(
'pyparsing'
)
selenium_standalone
.
load_package
(
'http://some_url/pyparsing.js'
)
with
pytest
.
raises
(
WebDriverException
,
match
=
"URI mismatch, attempting "
"to load package pyparsing"
):
selenium_standalone
.
load_package
(
'http://some_url/pyparsing.js'
)
assert
"Invalid package name or URI"
not
in
selenium_standalone
.
logs
assert
(
"URI mismatch, attempting "
"to load package pyparsing"
)
in
selenium_standalone
.
logs
def
test_invalid_package_name
(
selenium
):
selenium
.
load_package
(
'wrong name+$'
)
assert
"Invalid package name or URI"
in
selenium
.
logs
with
pytest
.
raises
(
WebDriverException
,
match
=
"Invalid package name or URI"
):
selenium
.
load_package
(
'wrong name+$'
)
selenium
.
clean_logs
()
selenium
.
load_package
(
'tcp://some_url'
)
assert
"Invalid package name or URI"
in
selenium
.
logs
with
pytest
.
raises
(
WebDriverException
,
match
=
"Invalid package name or URI"
):
selenium
.
load_package
(
'tcp://some_url'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment