Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit length of package ids to 64 characters #10368

Merged
merged 2 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private[data] final class IdStringImpl extends IdString {
*/
override type PackageId = String
override val PackageId: ConcatenableStringModule[PackageId, HexString] =
new ConcatenableMatchingStringModule("Daml-LF Package ID", "-_ ")
new ConcatenableMatchingStringModule("Daml-LF Package ID", "-_ ", 64)

/** Used to reference to leger objects like contractIds, ledgerIds,
* transactionId, ... We use the same type for those ids, because we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ class RefTest extends AnyFreeSpec with Matchers with EitherValues {
"reject too long string" in {
Party.fromString("p" * 255) shouldBe a[Right[_, _]]
Party.fromString("p" * 256) shouldBe a[Left[_, _]]
PackageId.fromString("p" * 64) shouldBe a[Right[_, _]]
PackageId.fromString("p" * 65) shouldBe a[Left[_, _]]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private[daml] object DamlLfEncoder extends App {
throw new Error("You should not get this error")
}

private val pkgId = Ref.PackageId.assertFromString("-self-")
private val pkgId = Ref.PackageId.assertFromString("self")
cocreature marked this conversation as resolved.
Show resolved Hide resolved

private def main() =
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ExceptionTest extends AnyWordSpec with Matchers with TableDrivenPropertyCh

implicit val defaultParserParameters: ParserParameters[this.type] = {
ParserParameters(
defaultPackageId = Ref.PackageId.assertFromString("-pkgId-"),
defaultPackageId = Ref.PackageId.assertFromString("pkgId"),
languageVersion = LanguageVersion.v1_dev,
)
}
Expand Down
11 changes: 2 additions & 9 deletions daml-lf/spec/daml-lf-1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,10 @@ instances when we want to avoid empty identifiers, escaping problems,
and other similar pitfalls. ::

PackageId strings
PackageIdString ::= ' PackageIdChars ' -- PackageIdString

Sequences of PackageId character
PackageIdChars ::= PackageIdChar -- PackageIdChars
| PackageIdChars PackageIdChar

PackageId character
PackageIdChar ∈ [a-zA-Z0-9\-_ ] -- PackageIdChar
PackageIdString ::= [a-zA-Z0-9\-_ ]{1,64} -- PackageIdString

PartyId strings
PartyIdString ∈ [a-zA-Z0-9:\-_ ]{1,255} -- PartyIdChar
PartyIdString ∈ [a-zA-Z0-9:\-_ ]{1,255} -- PartyIdString

PackageName strings
PackageNameString ∈ [a-zA-Z0-9:\-_]+ -- PackageNameString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object ValueGenerators {

// generate a junk identifier
val idGen: Gen[Identifier] = for {
n <- Gen.choose(1, 200)
n <- Gen.choose(1, 64)
packageId <- Gen
.listOfN(n, Gen.alphaNumChar)
.map(s => PackageId.assertFromString(s.mkString))
Expand Down