ปัญหาที่พบบ่อยอักขระหนีในสตริงที่ไม่คาดคิด '&'
อักขระหนีในสตริงที่ไม่คาดคิด '&'
หากคุณเห็นข้อความแสดงข้อผิดพลาดนี้:
Unexpected string escaped character '&'...เช่นในกรณีนี้:
{"message":"Unexpected string escaped character '&'","locations":[{"line":2596,"column":87}],"extensions":{"code":"gqlparser@4","specifiedBy":"https://spec.graphql.org/draft/#sec-Language"}}วิธีแก้ไขคือ: ปิดใช้งานแล้วเปิดใช้งานปลั๊กอินใหม่อีกครั้ง
หลังจากดำเนินการแล้ว หากคุณมีปลั๊กอินแคช DB คุณจะต้องล้างแคช DB ด้วย
คำอธิบายของปัญหา
ต้นเหตุของปัญหาคือ GraphQL query "translate-customposts" ถูกบันทึกไว้ในฐานข้อมูลอย่างผิดพลาด
ดูเหมือนว่าจะเกิดขึ้นเฉพาะในครั้งแรกที่ติดตั้งปลั๊กอิน และเฉพาะในกรณีที่มีการระบุ license ไว้ล่วงหน้า ดังนั้นข้อผิดพลาดนี้จึงเกิดขึ้นได้ยากมาก
ด้วยเหตุผลบางอย่าง (ซึ่งเราเองก็ไม่ทราบสาเหตุ) WordPress อาจทำให้เนื้อหาของ query เสียหายเมื่อทำการบันทึก
แม้ว่า query ต้นฉบับจะมีลักษณะดังนี้:
@underJSONObjectProperty(
by: { key: "coreMediaTextAlt" }
affectDirectivesUnderPos: [1, 6]
)
@underJSONObjectProperty(
by: { key: "from" }
affectDirectivesUnderPos: [1, 4],
)
@underEachJSONObjectProperty
@underEachArrayItem(
passValueOnwardsAs: "value"
)
@applyField(
name: "_sprintf",
arguments: {
string: "#(<!-- wp:media-text .*?-->\\n?<div .*><figure .*><img .*?alt=\\\")%s(\\\")#",
values: [$value]
},
setResultInResponse: true
)
@export(
as: "coreMediaTextAltReplacementsFrom",
)
@underJSONObjectProperty(
by: { key: "to" }
)
@export(
as: "coreMediaTextAltReplacementsTo",
)...WordPress จะบันทึกไว้ใน DB แบบนี้:
@underJSONObjectProperty(
by: { key: "coreMediaTextAlt" }
affectDirectivesUnderPos: [1, 6]
)
@underJSONObjectProperty(
by: { key: "from" }
affectDirectivesUnderPos: [1, 4],
)
@underEachJSONObjectProperty
@underEachArrayItem(
passValueOnwardsAs: "value"
)
@applyField(
name: "_sprintf",
arguments: {
string: "#(<!-- wp:media-text .*?-->\\n?<div><figure><img .*?alt=\\\")%s(\\\")#",
values: [$value]
},
setResultInResponse: true
)
@export(
as: "coreMediaTextAltReplacementsFrom",
)
@underJSONObjectProperty(
by: { key: "to" }
)
@export(
as: "coreMediaTextAltReplacementsTo",
)เมื่อปิดใช้งานแล้วเปิดใช้งานปลั๊กอินใหม่อีกครั้ง query จะถูกบันทึกลงในฐานข้อมูลใหม่ และปัญหาก็จะได้รับการแก้ไข