Skip to content

Commit bcff989

Browse files
authored
Accept LicenseRef license identifiers (#184)
1 parent 76c7152 commit bcff989

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/hex_licenses.erl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,30 @@ valid(<<"xlock">>) -> true;
665665
valid(<<"xpp">>) -> true;
666666
valid(<<"xzoom">>) -> true;
667667
valid(<<"zlib-acknowledgement">>) -> true;
668+
valid(<<"LicenseRef-", IdString/binary>>) -> valid_license_ref_idstring(IdString);
668669
valid(_) -> false.
670+
671+
valid_license_ref_idstring(<<>>) ->
672+
false;
673+
valid_license_ref_idstring(IdString) ->
674+
valid_license_ref_idstring(IdString, true).
675+
676+
valid_license_ref_idstring(<<>>, Valid) ->
677+
Valid;
678+
valid_license_ref_idstring(_, false) ->
679+
false;
680+
valid_license_ref_idstring(<<Char, Rest/binary>>, true) ->
681+
valid_license_ref_idstring(Rest, valid_license_ref_char(Char)).
682+
683+
valid_license_ref_char(Char) when Char >= $A, Char =< $Z ->
684+
true;
685+
valid_license_ref_char(Char) when Char >= $a, Char =< $z ->
686+
true;
687+
valid_license_ref_char(Char) when Char >= $0, Char =< $9 ->
688+
true;
689+
valid_license_ref_char($-) ->
690+
true;
691+
valid_license_ref_char($.) ->
692+
true;
693+
valid_license_ref_char(_) ->
694+
false.

test/hex_licenses_SUITE.erl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77
-include_lib("common_test/include/ct.hrl").
88

99
all() ->
10-
[license_test, invalid_license_test].
10+
[license_test, license_ref_test, invalid_license_test].
1111

1212
license_test(_Config) ->
1313
true = hex_licenses:valid(<<"MIT">>),
1414
ok.
1515

16+
license_ref_test(_Config) ->
17+
true = hex_licenses:valid(<<"LicenseRef-Journey">>),
18+
true = hex_licenses:valid(<<"LicenseRef-acme.1-2">>),
19+
false = hex_licenses:valid(<<"LicenseRef-">>),
20+
false = hex_licenses:valid(<<"LicenseRef-Journey License">>),
21+
false = hex_licenses:valid(<<"LicenseRef-Journey_License">>),
22+
ok.
23+
1624
invalid_license_test(_Config) ->
1725
false = hex_licenses:valid(<<"MICROSOFT">>),
1826
ok.

0 commit comments

Comments
 (0)