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 WKT length in repr #189

Merged
merged 7 commits into from
Sep 23, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pygeos/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ def test_to_wkt_multipoint_with_point_empty_errors():
pygeos.to_wkt(geom)


def test_repr_max_length():
# the repr is limited to 256 characters
geom = pygeos.linestrings(np.arange(1000), np.arange(1000))
assert len(repr(geom)) == 256


def test_repr_multipoint_with_point_empty():
# Test if segfault is prevented
geom = pygeos.multipoints([point, empty_point])
Expand Down
10 changes: 9 additions & 1 deletion src/pygeom.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
/* This initializes a global geometry type registry */
PyObject *geom_registry[1] = {NULL};

char* repr_fmt = "<pygeos.Geometry %s>";
/* the repr() format, the WKT is limited in length to 238 characters */
char* repr_fmt = "<pygeos.Geometry %.238s>";

/* Initializes a new geometry object */
PyObject *GeometryObject_FromGEOS(GEOSGeometry *ptr, GEOSContextHandle_t ctx)
Expand Down Expand Up @@ -105,6 +106,13 @@ static PyObject *GeometryObject_repr(GeometryObject *self)
PyErr_Clear();
return PyUnicode_FromFormat(repr_fmt, "Exception in WKT writer");
}
// Py_ssize_t length = PyUnicode_GetLength(result);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming these are no longer needed?

// if (length > 256) {

// }
// if (PyUnicode_GetLength(result) > 256) {

// }
return result;
}

Expand Down