Skip to content

Commit

Permalink
Escape < > characters in FastenPythonURI creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
MagielBruntink committed Mar 3, 2023
1 parent 368821a commit 4187fe4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.nio.file.Files;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;

import static eu.fasten.core.utils.TestUtils.getTestResource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class MetadataDatabasePythonPluginTest {

Expand Down Expand Up @@ -171,4 +178,13 @@ public void descriptionTest() {
+ " and writes graph of GIDs of callgraph to another Kafka topic.";
assertEquals(description, metadataDBExtension.description());
}

@Test
public void lambaTest() throws IOException {
var json = Files.readString(getTestResource("call-graph-with-lambda.json").toPath());
var cg = new PartialPythonCallGraph(new JSONObject(json));
var methods = cg.mapOfAllMethods();
var lambda = methods.get(1);
assertEquals(lambda.getUri(), "/main/test.%3Clambda1%3E()");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"product": "Test",
"forge": "PyPI",
"generator": "PyCG",
"depset": [],
"version": "TEST",
"timestamp": "0",
"modules": {
"internal": {
"/main": {
"sourceFile": "main.py",
"namespaces": {
"1": {
"namespace": "/main/test.<lambda1>()",
"metadata": {
"first": 1,
"last": 2
}
}
}
}
},
"external": {
}
},
"graph": {
"internalCalls": [],
"externalCalls": [],
"resolvedCalls": []
},
"nodes": 1,
"metadata": {
"loc": 1,
"time_elapsed": 1,
"max_rss": 1,
"num_files": 1
},
"sourcePath": "TEST"
}
6 changes: 4 additions & 2 deletions core/src/main/java/eu/fasten/core/data/FastenPythonURI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package eu.fasten.core.data;

import com.google.common.net.UrlEscapers;

import java.net.URI;

/** A class representing a Fasten URI for the Python language; it has to be considered experimental
Expand All @@ -29,7 +31,7 @@ public class FastenPythonURI extends FastenURI {
protected final boolean isFunction;

public FastenPythonURI(final String s) {
this(URI.create(s));
this(URI.create(UrlEscapers.urlFragmentEscaper().escape(s)));
}

public FastenPythonURI(final URI uri) {
Expand Down Expand Up @@ -88,7 +90,7 @@ public FastenPythonURI(final URI uri) {
* @return a {@link FastenPythonURI}.
*/
public static FastenPythonURI create(final String s) {
return new FastenPythonURI(URI.create(s));
return new FastenPythonURI(s);
}

/**
Expand Down

0 comments on commit 4187fe4

Please sign in to comment.