mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-27 05:01:57 +00:00
reworking recursion detection, still not happy with it...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
3d1598052a
commit
ac267b8c9f
@ -26,7 +26,7 @@ var pouchdbstore = require('./pwiki/store/pouchdb')
|
||||
|
||||
var store =
|
||||
module.store = {
|
||||
// XXX base localstorage...
|
||||
/* XXX base localstorage...
|
||||
__proto__: localstoragestore.localStorageStore,
|
||||
__prefix__: '--pwiki-root:',
|
||||
data: localStorage,
|
||||
|
||||
@ -505,7 +505,7 @@ module.Page =
|
||||
object.Constructor('Page', BasePage, {
|
||||
__parser__: parser.parser,
|
||||
|
||||
NESTING_RECURSION_THRESHOLD: 10,
|
||||
NESTING_RECURSION_TEST_THRESHOLD: 50,
|
||||
|
||||
// Filter that will isolate the page/include/.. from parent filters...
|
||||
ISOLATED_FILTERS: 'isolated',
|
||||
@ -523,11 +523,8 @@ object.Constructor('Page', BasePage, {
|
||||
// not present or broken.
|
||||
// NOTE: to force the system to fail set this to undefined.
|
||||
NOT_FOUND_ERROR: 'NotFoundError',
|
||||
|
||||
RECURSION_ERROR: 'RecursionError',
|
||||
|
||||
NOT_FOUND_TEMPLATE_ERROR: 'NotFoundTemplateError',
|
||||
|
||||
QUOTE_ACTION_PAGE: 'QuoteActionPage',
|
||||
|
||||
// Format:
|
||||
@ -709,7 +706,7 @@ object.Constructor('Page', BasePage, {
|
||||
?? new Set()
|
||||
|
||||
handler = handler
|
||||
?? async function(src){
|
||||
?? async function(src, state){
|
||||
return isolated ?
|
||||
{data: await this.get(src)
|
||||
.parse({
|
||||
@ -734,17 +731,18 @@ object.Constructor('Page', BasePage, {
|
||||
// recursion detected...
|
||||
if(seen.has(full)
|
||||
// nesting path recursion...
|
||||
// XXX a more general way to check would be to see if the
|
||||
// path resolves to the same source (done below) and
|
||||
// check if the context has changed -- i.e. if the paths
|
||||
// actually contain anything...
|
||||
|| (seen.size % (this.NESTING_RECURSION_THRESHOLD || 10) == 0
|
||||
&& new Set([...seen]
|
||||
.map(function(p){
|
||||
return page.get(p).match()[0] }))
|
||||
.size < seen.size)){
|
||||
|| (full.length % (this.NESTING_RECURSION_TEST_THRESHOLD || 50) == 0
|
||||
&& pwpath.split(full).length > 3
|
||||
&& await page.find() == await page.get('..').find()
|
||||
&& await page.find() == await page.get('../..').find())){
|
||||
if(recursive == null){
|
||||
yield page.get(page.RECURSION_ERROR).parse(state)
|
||||
console.warn(
|
||||
`@${key}(..): ${
|
||||
seen.has(full) ?
|
||||
'direct'
|
||||
: 'depth-limit'
|
||||
} recursion detected:`, seen)
|
||||
yield page.get(page.RECURSION_ERROR).parse()
|
||||
continue }
|
||||
// have the 'recursive' arg...
|
||||
yield base.parse(recursive, state)
|
||||
@ -752,7 +750,7 @@ object.Constructor('Page', BasePage, {
|
||||
seen.add(full)
|
||||
|
||||
// load the included page...
|
||||
var res = await handler.call(page, full)
|
||||
var res = await handler.call(page, full, state)
|
||||
depends.add(full)
|
||||
|
||||
// NOTE: we only track recursion down and not sideways...
|
||||
@ -771,7 +769,7 @@ object.Constructor('Page', BasePage, {
|
||||
yield* this.macros.include.call(this,
|
||||
'source',
|
||||
args, body, state, 'sources',
|
||||
async function(src){
|
||||
async function(src, state){
|
||||
return this.parse(this.get(src).raw, state) }) }),
|
||||
//
|
||||
// @quote(<src>)
|
||||
@ -1657,11 +1655,11 @@ module.System = {
|
||||
// NOTE: these are last resort pages, preferably overloaded in /Templates.
|
||||
//
|
||||
RecursionError: {
|
||||
text: 'RECURSION ERROR: @quote(../path)' },
|
||||
text: 'RECURSION ERROR: @source(../path)' },
|
||||
NotFoundError: {
|
||||
text: 'NOT FOUND ERROR: @quote(./path)' },
|
||||
text: 'NOT FOUND ERROR: @source(./path)' },
|
||||
NotFoundTemplateError: {
|
||||
text: 'NOT FOUND TEMPLATE ERROR: @quote(../path)' },
|
||||
text: 'NOT FOUND TEMPLATE ERROR: @source(../path)' },
|
||||
|
||||
DeletingPage: {
|
||||
text: 'Deleting: @source(../path)' },
|
||||
|
||||
11
pwiki2.js
11
pwiki2.js
@ -4,11 +4,12 @@
|
||||
* XXX BUG with non-BaseStore root, the paths under /Test/.. report
|
||||
* recursion errors when rendered by /tree...
|
||||
* /Test/tree -- works fine
|
||||
* XXX BUG service pages (NotFoundError, RecursionError, ...) now print
|
||||
* "[ native code ]" instead of the path and replacing @quote(..)
|
||||
* with @source(..) breaks things...
|
||||
* ...this seems to happen only if the root store is not
|
||||
* MetaStore/BaseStore...
|
||||
* this is affected by page.NESTING_RECURSION_THRESHOLD
|
||||
* XXX the problem is that we are still tracking state sideways...
|
||||
* ...likely via state transfer through @macro(..)
|
||||
* XXX not sure how it's connected to store type...
|
||||
* ...this turned out to trivial, local storage store simply
|
||||
* has more stuff...
|
||||
* XXX BUG: .get(..) does not seem to resolve to <store>.next...
|
||||
* XXX page search: make things invariant via .names
|
||||
* - if a page is in a system path and there are no alternatives
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user