Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -249,7 +249,12 @@ public static ScriptMetaData fromXContent(XContentParser parser) throws IOExcept
source = StoredScriptSource.fromXContent(parser, true);

if (exists == null) {
scripts.put(id, source);
// due to a bug (https://github.com/elastic/elasticsearch/issues/47593)
// scripts may have been retained during upgrade that include the old-style
// id of lang#id; these scripts are unreachable after 7.0, so they are dropped
if (id.contains("#") == false) {
scripts.put(id, source);
}
} else if (exists.getLang().equals(source.getLang()) == false) {
throw new IllegalArgumentException("illegal stored script, id [" + id + "] used for multiple scripts with " +
"different languages [" + exists.getLang() + "] and [" + source.getLang() + "]; scripts using the old " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;

public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaData> {

Expand Down Expand Up @@ -168,6 +169,42 @@ public void testLoadEmptyScripts() throws IOException {
assertWarnings("empty templates should no longer be used");
}

public void testOldStyleDropped() throws IOException {
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());

builder.startObject();
{
builder.startObject("painless#test");
{
builder.field("lang", "painless");
builder.field("source", "code");
}
builder.endObject();
builder.startObject("lang#test");
{
builder.field("lang", "test");
builder.field("source", "code");
}
builder.endObject();
builder.startObject("test");
{
builder.field("lang", "painless");
builder.field("source", "code");
}
builder.endObject();
}
builder.endObject();

XContentParser parser = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
BytesReference.bytes(builder).streamInput());
ScriptMetaData smd = ScriptMetaData.fromXContent(parser);
assertNull(smd.getStoredScript("painless#test"));
assertNull(smd.getStoredScript("lang#test"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check the size of the Map returned from getStoredScripts()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Added.

assertEquals(new StoredScriptSource("painless", "code", Collections.emptyMap()), smd.getStoredScript("test"));
assertEquals(1, smd.getStoredScripts().size());
}

@Override
protected boolean enableWarningsCheck() {
return true;
Expand Down