libexpr: Deprecate URL literals
Closes #437.
Change-Id: I9f67fc965bb4a7e7fd849e5067ac1cb3bab064cd
This commit is contained in:
parent
49d61b2e4b
commit
278fddc317
12
doc/manual/rl-next/deprecated-features.md
Normal file
12
doc/manual/rl-next/deprecated-features.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
synopsis: Deprecated URL literals
|
||||||
|
issues: [fj#437]
|
||||||
|
cls: [1736, 1735, 1744]
|
||||||
|
category: Breaking Changes
|
||||||
|
credits: [piegames, horrors]
|
||||||
|
---
|
||||||
|
|
||||||
|
URL literals have long been obsolete and discouraged of use, and now they are officially deprecated.
|
||||||
|
This means that all URLs must be properly put within quotes like all other strings.
|
||||||
|
|
||||||
|
To ease migration, they can still be enabled with `--extra-deprecated-features url-literals` for now.
|
|
@ -77,12 +77,6 @@
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, as a convenience, *URIs* as defined in appendix B of
|
|
||||||
[RFC 2396](http://www.ietf.org/rfc/rfc2396.txt) can be written *as
|
|
||||||
is*, without quotes. For instance, the string
|
|
||||||
`"http://example.org/foo.tar.bz2"` can also be written as
|
|
||||||
`http://example.org/foo.tar.bz2`.
|
|
||||||
|
|
||||||
- <a id="type-number" href="#type-number">Number</a>
|
- <a id="type-number" href="#type-number">Number</a>
|
||||||
|
|
||||||
Numbers, which can be *integers* (like `123`) or *floating point*
|
Numbers, which can be *integers* (like `123`) or *floating point*
|
||||||
|
|
|
@ -656,10 +656,10 @@ template<> struct BuildAST<grammar::expr::path> : p::maybe_nothing {};
|
||||||
|
|
||||||
template<> struct BuildAST<grammar::expr::uri> {
|
template<> struct BuildAST<grammar::expr::uri> {
|
||||||
static void apply(const auto & in, ExprState & s, State & ps) {
|
static void apply(const auto & in, ExprState & s, State & ps) {
|
||||||
bool noURLLiterals = ps.featureSettings.isEnabled(Xp::NoUrlLiterals);
|
bool URLLiterals = ps.featureSettings.isEnabled(Dep::UrlLiterals);
|
||||||
if (noURLLiterals)
|
if (!URLLiterals)
|
||||||
throw ParseError({
|
throw ParseError({
|
||||||
.msg = HintFmt("URL literals are disabled"),
|
.msg = HintFmt("URL literals are deprecated, allow using them with --extra-deprecated-features=url-literals"),
|
||||||
.pos = ps.positions[ps.at(in)]
|
.pos = ps.positions[ps.at(in)]
|
||||||
});
|
});
|
||||||
s.pushExpr<ExprString>(ps.at(in), in.string());
|
s.pushExpr<ExprString>(ps.at(in), in.string());
|
||||||
|
|
|
@ -488,7 +488,13 @@ struct FeatureSettings : Config {
|
||||||
Setting<std::set<DeprecatedFeature>> deprecatedFeatures{
|
Setting<std::set<DeprecatedFeature>> deprecatedFeatures{
|
||||||
this, {}, "deprecated-features",
|
this, {}, "deprecated-features",
|
||||||
R"(
|
R"(
|
||||||
Deprecated features that are allowed. (Currently there are none.)
|
Deprecated features that are allowed.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
deprecated-features = url-literals
|
||||||
|
```
|
||||||
|
|
||||||
The following deprecated feature features can be re-activated:
|
The following deprecated feature features can be re-activated:
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,16 @@ struct DeprecatedFeatureDetails
|
||||||
* feature, we either have no issue at all if few features are not added
|
* feature, we either have no issue at all if few features are not added
|
||||||
* at the end of the list, or a proper merge conflict if they are.
|
* at the end of the list, or a proper merge conflict if they are.
|
||||||
*/
|
*/
|
||||||
constexpr size_t numDepFeatures = 0;
|
constexpr size_t numDepFeatures = 1 + static_cast<size_t>(Dep::UrlLiterals);
|
||||||
|
|
||||||
constexpr std::array<DeprecatedFeatureDetails, numDepFeatures> depFeatureDetails = {{
|
constexpr std::array<DeprecatedFeatureDetails, numDepFeatures> depFeatureDetails = {{
|
||||||
|
{
|
||||||
|
.tag = Dep::UrlLiterals,
|
||||||
|
.name = "url-literals",
|
||||||
|
.description = R"(
|
||||||
|
Allow unquoted URLs as part of the Nix language syntax.
|
||||||
|
)",
|
||||||
|
},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
static_assert(
|
static_assert(
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace nix {
|
||||||
*/
|
*/
|
||||||
enum struct DeprecatedFeature
|
enum struct DeprecatedFeature
|
||||||
{
|
{
|
||||||
|
UrlLiterals
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -53,8 +53,13 @@ done
|
||||||
for i in lang/parse-okay-*.nix; do
|
for i in lang/parse-okay-*.nix; do
|
||||||
echo "parsing $i (should succeed)";
|
echo "parsing $i (should succeed)";
|
||||||
i=$(basename "$i" .nix)
|
i=$(basename "$i" .nix)
|
||||||
|
# Hard-code that these two files are allowed to use url literals (because they test them)
|
||||||
|
if [[ "$i" == "parse-okay-url" || "$i" == "parse-okay-regression-20041027" ]]
|
||||||
|
then
|
||||||
|
extraArgs="--extra-deprecated-features url-literals"
|
||||||
|
fi
|
||||||
if
|
if
|
||||||
expect 0 nix-instantiate --parse - < "lang/$i.nix" \
|
expect 0 nix-instantiate --parse ${extraArgs-} - < "lang/$i.nix" \
|
||||||
1> "lang/$i.out" \
|
1> "lang/$i.out" \
|
||||||
2> "lang/$i.err"
|
2> "lang/$i.err"
|
||||||
then
|
then
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# This test needs to be run with --extra-deprecated-features url-literals
|
||||||
{stdenv, fetchurl /* pkgconfig, libX11 */ }:
|
{stdenv, fetchurl /* pkgconfig, libX11 */ }:
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# This test needs to be run with --extra-deprecated-features url-literals
|
||||||
[ x:x
|
[ x:x
|
||||||
https://svn.cs.uu.nl:12443/repos/trace/trunk
|
https://svn.cs.uu.nl:12443/repos/trace/trunk
|
||||||
http://www2.mplayerhq.hu/MPlayer/releases/fonts/font-arial-iso-8859-1.tar.bz2
|
http://www2.mplayerhq.hu/MPlayer/releases/fonts/font-arial-iso-8859-1.tar.bz2
|
||||||
|
|
|
@ -87,15 +87,15 @@ namespace nix {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TrivialExpressionTest, urlLiteral) {
|
TEST_F(TrivialExpressionTest, urlLiteral) {
|
||||||
auto v = eval("https://nixos.org");
|
FeatureSettings mockFeatureSettings;
|
||||||
|
mockFeatureSettings.set("deprecated-features", "url-literals");
|
||||||
|
|
||||||
|
auto v = eval("https://nixos.org", true, mockFeatureSettings);
|
||||||
ASSERT_THAT(v, IsStringEq("https://nixos.org"));
|
ASSERT_THAT(v, IsStringEq("https://nixos.org"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TrivialExpressionTest, noUrlLiteral) {
|
TEST_F(TrivialExpressionTest, noUrlLiteral) {
|
||||||
ExperimentalFeatureSettings mockXpSettings;
|
ASSERT_THROW(eval("https://nixos.org"), Error);
|
||||||
mockXpSettings.set("experimental-features", "no-url-literals");
|
|
||||||
|
|
||||||
ASSERT_THROW(eval("https://nixos.org", true, mockXpSettings), Error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TrivialExpressionTest, withFound) {
|
TEST_F(TrivialExpressionTest, withFound) {
|
||||||
|
|
Loading…
Reference in a new issue