Skip to content

Commit

Permalink
Allow @ character in extension names (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamguo0 authored Nov 17, 2023
1 parent bd057a3 commit 8105f73
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/tleextension.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,16 @@ check_valid_extension_name(const char *extensionname)
* Check for alphanumeric character in extension name for now. Although
* this does prevent some naming schemes, it's a more straight forward
* prevention for preventing certain injection attacks due to the way the
* way we rely on functions currently. Allow the '_' or '-' character to
* provide a nice separator if desired.
* way we rely on functions currently. Allow the '_', '-', or '@'
* character to provide a nice separator if desired.
*/

while (extensionname[idx] != '\0')
{
if (!isalnum(extensionname[idx]) && extensionname[idx] != '_' && extensionname[idx] != '-')
if (!isalnum(extensionname[idx]) &&
extensionname[idx] != '_' &&
extensionname[idx] != '-' &&
extensionname[idx] != '@')
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid extension name: \"%s\"", extensionname),
Expand Down
45 changes: 45 additions & 0 deletions test/expected/pg_tle_management.out
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,51 @@ SELECT pgtle.available_extension_versions();
------------------------------
(0 rows)

-- install extension with '@' symbol in name
SELECT pgtle.install_extension
(
'foo@bar',
'1.0',
'Test TLE Functions',
$_pgtle_$
CREATE OR REPLACE FUNCTION at_func()
RETURNS INT AS $$
(
SELECT 42
)$$ LANGUAGE sql;
$_pgtle_$
);
install_extension
-------------------
t
(1 row)

SELECT pgtle.available_extensions();
available_extensions
------------------------------------
(foo@bar,1.0,"Test TLE Functions")
(1 row)

CREATE EXTENSION "foo@bar";
SELECT extname, extversion from pg_extension where extname='foo@bar';
extname | extversion
---------+------------
foo@bar | 1.0
(1 row)

SELECT at_func();
at_func
---------
42
(1 row)

DROP EXTENSION "foo@bar";
SELECT pgtle.uninstall_extension('foo@bar');
uninstall_extension
---------------------
t
(1 row)

-- Skip TransactionStmts
BEGIN;
SELECT pgtle.available_extension_versions();
Expand Down
22 changes: 22 additions & 0 deletions test/sql/pg_tle_management.sql
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,28 @@ SELECT pgtle.uninstall_extension('test42');

SELECT pgtle.available_extension_versions();

-- install extension with '@' symbol in name
SELECT pgtle.install_extension
(
'foo@bar',
'1.0',
'Test TLE Functions',
$_pgtle_$
CREATE OR REPLACE FUNCTION at_func()
RETURNS INT AS $$
(
SELECT 42
)$$ LANGUAGE sql;
$_pgtle_$
);

SELECT pgtle.available_extensions();
CREATE EXTENSION "foo@bar";
SELECT extname, extversion from pg_extension where extname='foo@bar';
SELECT at_func();
DROP EXTENSION "foo@bar";
SELECT pgtle.uninstall_extension('foo@bar');

-- Skip TransactionStmts
BEGIN;
SELECT pgtle.available_extension_versions();
Expand Down

0 comments on commit 8105f73

Please sign in to comment.