Skip to content

Commit e49e295

Browse files
authored
Merge pull request #642 from nextcloud/bugfix/issue640
Fixes minor errors in displaying ingredients and instructions
2 parents e5b3887 + cf2e962 commit e49e295

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## [Unreleased]
22

3+
### Fixed
4+
- Minor errors in displaying ingredients and instructions
5+
[#642](https://github.com./nextcloud/cookbook/pull/642) @seyfeb
6+
37
## 0.8.3 - 2021-03-03
48

59
### Fixed

src/components/RecipeIngredient.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
export default {
1717
name: "RecipeIngredient",
1818
props: {
19+
/* Ingredient HTML string to display. Content should be sanitized.
20+
*/
1921
ingredient: {
2022
type: String,
2123
default: "",
@@ -33,11 +35,9 @@ export default {
3335
computed: {
3436
displayIngredient() {
3537
if (this.isHeader()) {
36-
return window.escapeHTML(
37-
this.ingredient.substring(this.headerPrefix.length)
38-
)
38+
return this.ingredient.substring(this.headerPrefix.length)
3939
}
40-
return window.escapeHTML(this.ingredient)
40+
return this.ingredient
4141
},
4242
},
4343
methods: {

src/components/RecipeInstruction.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<template>
2-
<li :class="{ done: isDone }" @click="toggleDone">{{ instruction }}</li>
2+
<li :class="{ done: isDone }" @click="toggleDone" v-html="instruction"></li>
33
</template>
44

55
<script>
66
export default {
77
name: "RecipeInstruction",
88
props: {
9+
/* Instruction HTML string to display. Content should be sanitized.
10+
*/
911
instruction: {
1012
type: String,
1113
default: "",

src/components/RecipeView.vue

+4-13
Original file line numberDiff line numberDiff line change
@@ -332,20 +332,20 @@ export default {
332332
333333
if (this.$store.state.recipe.description) {
334334
recipe.description = this.convertRecipeReferences(
335-
this.escapeHtml(this.$store.state.recipe.description)
335+
window.escapeHTML(this.$store.state.recipe.description)
336336
)
337337
}
338338
339339
if (this.$store.state.recipe.recipeIngredient) {
340340
recipe.ingredients = Object.values(
341341
this.$store.state.recipe.recipeIngredient
342-
).map((i) => this.convertRecipeReferences(this.escapeHtml(i)))
342+
).map((i) => this.convertRecipeReferences(window.escapeHTML(i)))
343343
}
344344
345345
if (this.$store.state.recipe.recipeInstructions) {
346346
recipe.instructions = Object.values(
347347
this.$store.state.recipe.recipeInstructions
348-
).map((i) => this.convertRecipeReferences(this.escapeHtml(i)))
348+
).map((i) => this.convertRecipeReferences(window.escapeHTML(i)))
349349
}
350350
351351
if (this.$store.state.recipe.keywords) {
@@ -389,7 +389,7 @@ export default {
389389
390390
if (this.$store.state.recipe.tool) {
391391
recipe.tools = this.$store.state.recipe.tool.map((i) =>
392-
this.convertRecipeReferences(this.escapeHtml(i))
392+
this.convertRecipeReferences(window.escapeHTML(i))
393393
)
394394
}
395395
@@ -466,15 +466,6 @@ export default {
466466
})
467467
},
468468
methods: {
469-
escapeHtml(unsafeString) {
470-
return unsafeString
471-
.replace(/&/g, "&amp;")
472-
.replace(/~/g, "&#732;")
473-
.replace(/</g, "&lt;")
474-
.replace(/>/g, "&gt;")
475-
.replace(/"/g, "&quot;")
476-
.replace(/'/g, "&#039;")
477-
},
478469
convertRecipeReferences(text) {
479470
const re = /(^|\s|[,._+&?!-])#r\/(\d+)(?=$|\s|[.,_+&?!-])/g
480471
const converted = text.replace(

src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ import AppMain from "./components/AppMain.vue"
9494
// eslint-disable-next-line no-param-reassign
9595
window.escapeHTML = function escapeHTML(text) {
9696
return text.replace(
97-
/["&'/<>]/g,
97+
/["&'<>]/g,
9898
(a) =>
9999
({
100100
"&": "&amp;",

0 commit comments

Comments
 (0)