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

JavaScriptFragment.asJson() #5108

Merged
merged 8 commits into from
Jan 27, 2024
Merged

Conversation

labkey-matthewb
Copy link
Contributor

@labkey-matthewb labkey-matthewb commented Jan 9, 2024

replace Jsp.unsafe() with JavaScriptFragment.unsafe() in <script> blocks replace new ObjectMapper() with JsonUtil.DEFAULT_MAPPER or JsonUtil.createDefaultMapper()

Rationale

Related Pull Requests

Changes

  • eliminate use of new ObjectMapper()
  • new JavaScriptFragment helpers: asJson() asString()
  • remove usages of unsafe()/text() from <script> blocks (replace with q() or JavaScriptFragment)

replace Jsp.unsafe() with JavaScriptFragment.unsafe() in <script> blocks
replace new ObjectMapper() with JsonUtil.DEFAULT_MAPPER or JsonUtil.createDefaultMapper()
@labkey-matthewb labkey-matthewb marked this pull request as ready for review January 16, 2024 19:23
@@ -388,7 +389,7 @@ private String getBestJson(String currentValue, String newValue, String serverSe
}

// Rather than overwrite the current json map, merge the new with the current.
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonUtil.createDefaultMapper();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be JsonUtil.DEFAULT_MAPPER

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've taken to using DEFAULT_MAPPER when I can inline the whole usage. Just a style choice and speeds up converting code (what does readerForUpdating() do? beats me.).

Copy link
Contributor

@labkey-adam labkey-adam left a comment

Choose a reason for hiding this comment

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

There's an h() to q() conversion in there somewhere

@@ -244,7 +245,7 @@

Ext4.onReady(function()
{
var datasetInfo = <%=unsafe(JsonUtil.DEFAULT_MAPPER.writeValueAsString(datasetInfo))%>;
var datasetInfo = <%=JavaScriptFragment.asJson(datasetInfo)%>;
var store = LABKEY.study.DataViewUtil.getViewCategoriesStore({
storeId : '<%=h(storeId)%>',
Copy link
Contributor

Choose a reason for hiding this comment

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

That looks wrong

Copy link
Contributor

Choose a reason for hiding this comment

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

Meaning line 250

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume this is some Ext weirdness where you have to htmlEncode() id's so they don't get injected into the html? I don't think I changed this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

configRequestabilityRules.jsp has a strange use of h() which I changed to qh(), not sure if it's wrong.

@labkey-matthewb labkey-matthewb merged commit 9d35985 into develop Jan 27, 2024
9 of 10 checks passed
@labkey-matthewb labkey-matthewb deleted the fb_javascriptfragment_asjson branch January 27, 2024 01:02
labkey-jeckels pushed a commit that referenced this pull request Jan 29, 2024
* JavaScriptFragment.asJson()
replace Jsp.unsafe() with JavaScriptFragment.unsafe() in <script> blocks
replace new ObjectMapper() with JsonUtil.DEFAULT_MAPPER or JsonUtil.createDefaultMapper()

* use HtmlString for html

* JavaScriptFragment.asString()

* typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants