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

Fix promises at EOF #4097

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Units/parser-html.r/jsp.d/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
JSP tags shouldn't trigger the PHP parser.

This used to happen and trigger an infinite loop of a ping-pong effect
with the HTML parser asking the PHP parser to parse the JSP block, and
the PHP parser, not recognizing the input, asking the HTML one to deal
with it. Rinse and repeat.
2 changes: 2 additions & 0 deletions Units/parser-html.r/jsp.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--extras='*'
1 change: 1 addition & 0 deletions Units/parser-html.r/jsp.d/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%=
3 changes: 3 additions & 0 deletions Units/parser-php.r/wp-guest.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--sort=no
--extras=+rg
--fields=+rln
14 changes: 14 additions & 0 deletions Units/parser-php.r/wp-guest.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
top input.php /^<div id="top">$/;" I line:3 language:HTML roles:def
inner input.php /^ <div class="inner">$/;" c line:4 language:HTML roles:attribute
logo input.php /^<div id="logo">$/;" I line:6 language:HTML roles:def
pages input.php /^<div id="pages">$/;" I line:12 language:HTML roles:def
menubar input.php /^<ul class="menubar" id="menubar">$/;" c line:13 language:HTML roles:attribute
menubar input.php /^<ul class="menubar" id="menubar">$/;" I line:13 language:HTML roles:def
body input.php /^<div id="body">$/;" I line:26 language:HTML roles:def
content input.php /^ <main id="content">$/;" I line:27 language:HTML roles:def
post input.php /^ <article class="post" id="post-/;" c line:31 language:HTML roles:attribute
post- input.php /^ <article class="post" id="post-/;" I line:31 language:HTML roles:def
storybody input.php /^ <div class="storybody"><br \/>/;" c line:37 language:HTML roles:attribute
postmetadata input.php /^ <p class="postmetadata"><\/p>$/;" c line:38 language:HTML roles:attribute
storybody input.php /^ <div class="storybody">/;" c line:41 language:HTML roles:attribute
left input.php /^ <aside id="left">/;" I line:52 language:HTML roles:def
55 changes: 55 additions & 0 deletions Units/parser-php.r/wp-guest.d/input.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php get_header(); ?>

<div id="top">
<div class="inner">
<br clear="all" />
<div id="logo">
<h2><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h2>
<p>
<?php bloginfo('description'); ?>
</p>
</div>
<div id="pages">
<ul class="menubar" id="menubar">
<li><a href="<?php bloginfo('url'); ?>">Accueil</a></li>
<?php montheme_list_pages( array( 'depth' => 1 ) ); ?>
</ul>
<!--[if !IE]><-->
<script type="text/javascript">
initMenu (document.getElementById ('menubar'), 0);
</script>
<!--><![endif]-->
</div>
</div>
</div>

<div id="body">
<main id="content">

<?php if (have_posts()) : while (have_posts()) : the_post(); ?><br /><br />

<article class="post" id="post-<?php the_ID(); ?>">

<div class="storycontent">

<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

<div class="storybody"><br /><?php the_content(__('(more...)')); ?></div>
<p class="postmetadata"></p>

</div>
<div class="storybody"><?php comments_template(); // Get wp-comments.php template ?></div>
</article>


<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

<?php posts_nav_link(' &#8212; ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?>

</main>
<aside id="left"><?php get_sidebar(); ?></aside>
</div>

<?php get_footer(); ?>
9 changes: 7 additions & 2 deletions main/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef struct sInputFile {
vString *path; /* path of input file (if any) */
vString *line; /* last line read from file */
const unsigned char* currentLine; /* current line being worked on */
size_t currentLineEndOffset;
MIO *mio; /* MIO stream used for reading the file */
compoundPos filePosition; /* file position of current line */
unsigned int ungetchIdx;
Expand Down Expand Up @@ -159,8 +160,7 @@ extern int getInputLineOffset (void)
/* When EOF is saw, currentLine is set to NULL.
* So the way to calculate the offset at the end of file is tricky.
*/
ret = (mio_tell (File.mio) - (File.bomFound? 3: 0))
- getInputFileOffsetForLine(File.input.lineNumber);
ret = File.currentLineEndOffset - File.ungetchIdx;
}
else
{
Expand Down Expand Up @@ -766,6 +766,7 @@ extern bool openInputFile (const char *const fileName, const langType language,
mio_getpos (File.mio, &File.filePosition.pos);
File.filePosition.offset = StartOfLine.offset = mio_tell (File.mio);
File.currentLine = NULL;
File.currentLineEndOffset = 0;

File.line = vStringNewOrClear (File.line);
File.ungetchIdx = 0;
Expand Down Expand Up @@ -804,6 +805,7 @@ extern void resetInputFile (const langType language, bool resetLineFposMap_)
mio_getpos (File.mio, &File.filePosition.pos);
File.filePosition.offset = StartOfLine.offset = mio_tell (File.mio);
File.currentLine = NULL;
File.currentLineEndOffset = 0;

Assert (File.line);
vStringClear (File.line);
Expand Down Expand Up @@ -1032,7 +1034,10 @@ extern int getcFromInputFile (void)
{
vString* const line = iFileGetLine (false);
if (line != NULL)
{
File.currentLine = (unsigned char*) vStringValue (line);
File.currentLineEndOffset = vStringLength (line);
}
if (File.currentLine == NULL)
c = EOF;
else
Expand Down
2 changes: 1 addition & 1 deletion parsers/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static void readToken (tokenInfo *const token, bool skipComments)
ungetcToInputFile (d);
token->type = TOKEN_OTHER;
}
else if (d == '?' || d == '%')
else if (d == '?')
{
skipOtherScriptContent(d);
goto getNextChar;
Expand Down
9 changes: 6 additions & 3 deletions parsers/php.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,13 +861,14 @@ static bool isOpenScriptLanguagePhp (int c)
return true;
}

static int findPhpStart (void)
static int findPhpStart (int *tagStartLineOffset)
{
int c;
do
{
if ((c = getcFromInputFile ()) == '<')
{
*tagStartLineOffset = getInputLineOffset () - 1;
c = getcFromInputFile ();
/* <?, <?= and <?php, but not <?xml */
if (c == '?')
Expand Down Expand Up @@ -933,13 +934,15 @@ static void readToken (tokenInfo *const token)
unsigned long startSourceLineNumber = getSourceLineNumber ();
unsigned long startLineNumber = getInputLineNumber ();
int startLineOffset = getInputLineOffset ();
int endLineOffset;

c = findPhpStart ();
c = findPhpStart (&endLineOffset);
if (c != EOF)
InPhp = true;
else
endLineOffset = getInputLineOffset ();

unsigned long endLineNumber = getInputLineNumber ();
int endLineOffset = getInputLineOffset ();

makePromise ("HTML", startLineNumber, startLineOffset,
endLineNumber, endLineOffset, startSourceLineNumber);
Expand Down
Loading