Open
Conversation
mitonize
added a commit
that referenced
this pull request
Mar 22, 2026
自動エスケープ機能、script文脈での記述性と安全性を両立させるScopeマクロ(糖衣構文)の導入
#### 主な変更点
- 自動エスケープの実装
- 出力文脈ごとのエスケープ適用(HTML本文、属性、SCRIPT、STYLE、TEXTAREA/PREなど)
- 既にエスケープ済みであるかを判定して二重エスケープを抑制
- 明示的に非エスケープ出力したい場合は MAYAA_SCOPE_RAW もしくは ${=...} を使用
- HTMLコメントによるページ単位の自動エスケープ設定のディレクティブ機能追加(m:autoEscape)
- scriptタグ内での`${}` 記法でJS構文が維持できるように下記のScopeマクロを糖衣構文として追加
- MAYAA_SCOPE
- MAYAA_SCOPE_AS_STRING
- MAYAA_SCOPE_WITH_STRINGIFY
- MAYAA_SCOPE_RAW
- Scopeマクロ展開時に使用するへるぱ関数をグローバル関数として追加
- _mayaa_scope
- _mayaa_scope_as_string
- _mayaa_scope_with_stringify
- 診断イベント記録機構の導入
- autoEscape無効時でも危険文字を検知した際の警告を記録
(別の機能として診断ログをオンラインで確認できるようにする予定)
- レンダリング時にディレクティブ情報を反映するための `DirectiveProcessor` を追加
#### 仕様変更点(従来との差分)
- **シングルクオートのエスケープ仕様を文脈ごとに明確化**
- HTML本文・TEXTAREA/PREでは `'`(シングルクオート)はエスケープしない
- HTML属性値では `'` を `'` にエスケープ
- 既存テストの期待値もこの仕様に合わせて変更
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CDATAは入れ子が許されていない。
CDATAProcessorを入れ子で使用すると各プロセッサで <![CDATA[ および ]]> を出力するため
意図せずCDATAが閉じてしまう。
このため、ネストレベルを管理して、内側のCDATAProcessorでは <![CDATA[ および ]]> を出力しないようにする。
入れ子を検知した段階で例外を出力した方がよければコメントください。