Skip to content

Commit 7d9930f

Browse files
committed
First part of #1039 (content redacted marker)
1 parent 7fb83a3 commit 7d9930f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/main/java/com/fasterxml/jackson/core/base/ParserBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ protected ContentReference _contentReference() {
15341534
if (JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION.enabledIn(_features)) {
15351535
return _ioContext.contentReference();
15361536
}
1537-
return _contentReferenceNoSource();
1537+
return _contentReferenceRedacted();
15381538
}
15391539

15401540
/**
@@ -1549,8 +1549,8 @@ protected ContentReference _contentReference() {
15491549
*
15501550
* @since 2.16
15511551
*/
1552-
protected ContentReference _contentReferenceNoSource() {
1553-
return ContentReference.unknown();
1552+
protected ContentReference _contentReferenceRedacted() {
1553+
return ContentReference.redacted();
15541554
}
15551555

15561556
protected static int[] growArrayBy(int[] arr, int more)

src/main/java/com/fasterxml/jackson/core/io/ContentReference.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ public class ContentReference
3535
protected final static ContentReference UNKNOWN_CONTENT =
3636
new ContentReference(false, null);
3737

38+
/**
39+
* As content will be redacted by default in Jackson 2.16 and later,
40+
* we'll use a new marker reference for slightly different description
41+
* from "unknown", to indicate explicit removal of source/content reference
42+
* (as opposed to it missing from not being available or so)
43+
*
44+
* @since 2.16
45+
*/
46+
protected final static ContentReference REDACTED_CONTENT =
47+
new ContentReference(false, null);
48+
3849
/**
3950
* Include at most first 500 characters/bytes from contents; should be enough
4051
* to give context, but not cause unfortunate side effects in things like
@@ -100,6 +111,20 @@ public static ContentReference unknown() {
100111
return UNKNOWN_CONTENT;
101112
}
102113

114+
/**
115+
* Accessor for getting a placeholder when actual content
116+
* is not to be exposed: different from {@link #unknown()} where
117+
* content is not available to be referenced.
118+
*
119+
* @return Placeholder instance to use in cases where reference is explicitly
120+
* blocked, usually for security reasons.
121+
*
122+
* @since 2.16
123+
*/
124+
public static ContentReference redacted() {
125+
return REDACTED_CONTENT;
126+
}
127+
103128
public static ContentReference construct(boolean isContentTextual, Object rawContent) {
104129
return new ContentReference(isContentTextual, rawContent);
105130
}

0 commit comments

Comments
 (0)